結果を以下のような多次元配列にしてみてください
注:それがテーブルdetails.details_no
の主キーであり、次のような結果が必要であると想定していますdetails
john
1 test log for john 2013-08-01
2 another test log for john 2013-08-02
peter
3 test log for peter 213-08-02
次の方法で取得できます
...
$qry = "
SELECT
info.info_id,
info.name,
details.details_no,
details.log,
details.date
FROM
info
JOIN details ON (details.details_id = info.info_id)
";
$result = mysqli_query($your_db_link,$qry)
$data = array();
while($row = mysqli_fetch_array($result)){
$data[$row["info_id"]]["name"] = $row["name"];
$data[$row["info_id"]]["logs"][$row["details_no"]] = array(
"log"=>$row["log"],
"date"=>$row["date"],
);
}
次のような配列になります。
$data = array(
"1" => array(
"name" => "john",
"logs" => array(
"1" => array(
"log" => "test log for john",
"date" => "2013-08-01",
),
"2" => array(
"log" => "another test log for john",
"date" => "2013-08-02",
),
),
),
"2" => array(
"name" => "peter",
"logs" => array(
"3" => array(
"log" => "test log for peter",
"date" => "2013-08-02",
),
),
),
);
次に、次のように表示できます。
echo "<table>";
foreach($data as $value){
echo "<tr><td colspan='3'>".$value["name"]."</td></tr>";
foreach($value["logs"] as $subkey => $subvalue){
echo "<tr>";
echo "<td>".$subkey."</td>";
echo "<td>".$subvalue["log"]."</td>";
echo "<td>".$subvalue["date"]."</td>";
echo "</tr>";
}
}
echo "</table>";
次のような結果になります。
<table>
<tr>
<td colspan='3'>john</td>
</tr>
<tr>
<td>1</td>
<td>test log for john</td>
<td>2013-08-01</td>
</tr>
<tr>
<td>2</td>
<td>another test log for john</td>
<td>2013-08-02</td>
</tr>
<tr>
<td colspan='3'>peter</td>
</tr>
<tr>
<td>3</td>
<td>test log for peter</td>
<td>2013-08-02</td>
</tr>
</table>