php - Display MYSQL query result in horizontal view -


we have employee attendance system in mysql database dont have reporting capability, trying generate reports using php.

let me explain :

employee punch in , punch out daily. these punch ins , outs stored in mysql database table ( attendance). table contain 5 fields punch in, punchout, employeeid, note, attendanceid. our employee names , other details stored in other table ( employee).

my query want generate report using these 2 tables in horizontal view.

example :

column1 : employee name column2 : punchin column3 : punchout column4 : punchin column : punchout

i able generate daily report employees looking generate weekly/monthly report.

pls help.

thanks, raj

it sounds trying pivot query (switch rows , columns). mysql has no support this, can simulated. easier data need , parse php, however.

it sounds (and guess) want employee first column , punch ins/outs in same row employee.

here's crack @ want do:

$data = select_all_relevant_data_with_mysql(); $employees = array(); while ($row = $data->fetch()) {    $employees[$row['employee']][] = array(       'in' => $row['punchin']       , 'out' => $row['punchout']    ); } 

(note generate undefined index notices each employee entry. should handle this, double code there).

now have punchin/out data arranged per employee (hopefully in order, mysql can handle order by).

now link:

foreach ($employees $name => $punches) {    echo <<<html       <tr><td>$name</td> html;    foreach ($punches $punch) {       echo <<<html          <td>$punch[in]</td><td>$punch[out]</td> html;    }    echo '</tr>'; } 

i suggest using templating system phptal kind of thing. shameless plug :)


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -