displaying php mysql query result with one to many relationship -


heres sample table:

info table info_id     name   1           john   2           peter ------------------------   details table   details_id      log                               date   1            test log john                  2013-08-01   1            log john               2013-08-02   2            test log peter                 2013-08-02 

here's sample query:

select info.info_id, info.name, details.details_no, details.log, details.date  info join details on details.details_id = info.info_id  group info.info_id   

and here's display want achieve:

john   1     test log john            2013-08-01   1     test log john    2013-08-02    peter   2     test log peter           213-08-02   

i have tried using foreach loop , execute foreach loop inside first loop.

please guys

you going have take data , make array want.

$data = array(); foreach ($result $item) {     $key = $item['name']; // or $item['info_id']     if (!isset($data[$key])) {         $data[$key] = array();     }      $data[$key][] = $item; }  // build table new $data array 

edit

this example. amaster507 points out, if name field isn't unique, need build array on unique key. not terribly different this, change instances of $item['name'] $item['info_id'].


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -