rbarnett Posted June 17, 2008 Share Posted June 17, 2008 I have a query that I display to the screen using a foreach. The query has driver id, date, miles, odometer reading and when I display the results I want to display each miles and odometer reading by date instead of showing multiple driver ids with the the miles and odometer reading for each. Here is the related code: $sql = "select distinct driver_id, username, client_employee_id, last_name, first_name, name, miles, odometer, date from drivers join driver_groups dg using(driver_group_id) join users u using(contact_id) join contacts c using(contact_id) join monthly_mileages using (driver_id) where company_id=23342 and date BETWEEN '2008-2-01' AND '2008-5-01' ORDER BY last_name"; $aOutput = $oDb->getArrayOfArrays("$sql"); // returns result of query echo '<table border="1"><tr> <td>Driver ID</td><td>Miles</td><td>Odometer</td> </tr>'; foreach ($aOutput as $value) { echo '<tr><td>'.$value['driver_id'].'</td><td>'.$value['date'].'</td><td>'.$value['miles'].'</td><td>'.$value['odometer'].'</td></tr>'; } echo '</table>'; The html output looks like: Driver ID Date Miles Odometer 24013 2008-05-01 1241 35712 24013 2008-04-01 1819 34051 24142 2008-05-01 1487 18240 24021 2008-04-01 29 84216 24021 2008-05-01 179 85419 24472 2008-05-01 1335 69071 24472 2008-04-01 1942 67586 What I want to do instead is have the html output to look like: Driver ID May 08 Miles Odometer 24013 2008-05-01 1241 35712 24013 2008-04-01 1819 34051 24142 2008-05-01 1487 18240 24021 2008-04-01 29 84216 24021 2008-05-01 179 85419 24472 2008-05-01 1335 69071 24472 2008-04-01 1942 67586 Link to comment https://forums.phpfreaks.com/topic/110626-array-newbie-question/ Share on other sites More sharing options...
rbarnett Posted June 17, 2008 Author Share Posted June 17, 2008 My apologies: I posted before I finished editing and didn't realize it was posted so I ended up posting it again as a different post. Please ignore this or if someone knows how to remove this that would be great. Sorry Link to comment https://forums.phpfreaks.com/topic/110626-array-newbie-question/#findComment-567558 Share on other sites More sharing options...
craygo Posted June 17, 2008 Share Posted June 17, 2008 maybe it's me but your 2 examples look identical accept for the may08 part up top. Link to comment https://forums.phpfreaks.com/topic/110626-array-newbie-question/#findComment-567559 Share on other sites More sharing options...
kenrbnsn Posted June 17, 2008 Share Posted June 17, 2008 Locked Link to comment https://forums.phpfreaks.com/topic/110626-array-newbie-question/#findComment-567565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.