php - How to load two fields returned by a query into an associative array? -
i have complex query structure:
select driver, travel travels ...
returns this:
david paris david oslo jhon amsterdam david madrid marco barcelona jhon rome
well, want return information in 2 parts. mean, first of array of drivers contains:
david jhon marco
and according user's choice want travels of driver. assuming choose david, return array with:
paris oslo madrid
i know can separating 2 queries, but, said, complex query on database many records in way i'd save time.
i'm using php... how this?, associative array? give me example, please?
i hope clear in explanation. in advance.
for both save them first in array:
while ($row = $result->fetch_object()) { // mysqli. mysql use mysql_fetch_object($result) $travel[$row->driver][] = $row->travel; }
for first:
$drivers = array_keys($travel);
for second:
$locations = $travel[$driver];
Comments
Post a Comment