0

I'm querying a MySQL database for reservations, like so

$query = "
SELECT * 
  FROM tbl_reservations r
  LEFT 
  JOIN tbl_admins a
    ON a.admin_id = r.reservation_driverID  
 WHERE reservation_time >= :pickup 
   AND reservation_endtime <= :endtime
   AND reservation_status = 0 
 ORDER 
    BY reservation_time DESC
";

$getRes = $pdo->prepare($query);
$getRes->bindparam(":pickup", $pickup);
$getRes->bindparam(":endtime", $dropoff);
$getRes->execute();

$reservations = $getRes->fetchAll(PDO::FETCH_ASSOC);

This gives me back a nice list of reservations into one single array.

I'm wondering, using PHP, what would be the best way to loop though this array of objects and split it into multiple arrays, where each array would contain all of the trips for an individual driver (so, filtering by tbl_admins.admin_id)

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Adam G
  • 1,188
  • 10
  • 24
  • 1
    It would be nice if you could show what's actually returned by your query. I would say that any filtering is best done in SQL rather than PHP, so that your query won't return large result sets most of which will be thrown away by your PHP code. – Alexander van Oostenrijk Dec 20 '19 at 18:33
  • See https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query – Strawberry Dec 20 '19 at 18:35

0 Answers0