Jump to content

Array newbie question


rbarnett

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.