php - how to display checkin table in one row -


i have table looks this.

pers_id pers_name   pers_date   pers_date_attend_ind 431        bacon    1/14/2013   n 431        bacon    1/27/2013   n 431        bacon    1/28/2013   n 431        bacon    2/17/2013   n 

i'd display in php like

        <date 1>    <date 2>   <date 3> bacon       n          n          n  

i'm @ loss how that.

assume $rows variable looks after fetching results this:

$rows = array(0 => array('pers_id' => 431, 'pers_name' => 'bacon', 'pers_date' => '1/14/2013', 'pers_date_attend_ind' => 'n'),               1 => array('pers_id' => 431, 'pers_name' => 'bacon', 'pers_date' => '1/27/2013', 'pers_date_attend_ind' => 'n'),               2 => array('pers_id' => 431, 'pers_name' => 'bacon', 'pers_date' => '1/28/2013', 'pers_date_attend_ind' => 'n'),               3 => array('pers_id' => 431, 'pers_name' => 'bacon', 'pers_date' => '2/17/2013', 'pers_date_attend_ind' => 'n'),         ); 

then played array make this:

array (     [431] => array         (             [name] => bacon             [dates] => array                 (                     [1/14/2013] => n                     [1/27/2013] => n                     [1/28/2013] => n                     [2/17/2013] => n                 )          )  ) 

using foreach loop:

foreach($rows $value) {     $array[$value['pers_id']]['name'] = $value['pers_name'];     $array[$value['pers_id']]['dates'][$value['pers_date']] = $value['pers_date_attend_ind']; } 

now looks better table(s) preparation. created function returns table(s) set in question based on modified array.

function generate_table($array) {     $html = '';     foreach($array $value)     {         $html .= '<table>'; // start table inside loop. looks better due each member may have different number of date count.         $html .= '<tr>';         $html .= '<td>&nbsp;</td>';         foreach($value['dates'] $k => $v)         {             $html .= '<td>' . $k . '</td>';         }         $html .= '</tr>';         $html .= '<tr>';         $html .= '<td>' . $value['name'] . '</td>';         foreach($value['dates'] $v)         {             $html .= '<td>' . $v . '</td>';         }         $html .= '</tr>';         $html .= '</table>';     }     return $html; } 

this function looks bit nasty, works. it's on improve function if want.

live previews

preview of result

results...


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -