Heres A Sample Table:
info table
info_id name
1 john
2 peter
------------------------
details table
details_id log date
1 test log for john 2013-08-01
1 another log for john 2013-08-02
2 test log for peter 2013-08-02
Here's my Sample Query:
SELECT info.info_id, info.name, details.details_no, details.log, details.date
FROM info JOIN details ON details.details_id = info.info_id
GROUP BY info.info_id
And Here's display i want to achieve:
john
1 test log for john 2013-08-01
1 another test log for john 2013-08-02
peter
2 test log for peter 213-08-02
I have tried using foreach loop and then execute another foreach loop inside the first loop.
Please Help Guys
解决方案
You are probably going to have to take the data and make the array that you want.
$data = array();
foreach ($result as $item) {
$key = $item['name']; // or $item['info_id']
if (!isset($data[$key])) {
$data[$key] = array();
}
$data[$key][] = $item;
}
// Build your table with the new $data array
EDIT
This is just an example. As amaster507 points out, if your name field isn't unique, you will need to build your array on a unique key. Not terribly different from this, as you could probably just change instances of $item['name'] to $item['info_id'].