merging arrays from a mysql_fetch_array
| From: | Simon R Jones | Date: | Wed, 23 Aug 2000 10:04:42 +0000 |
| Subject: | merging arrays from a mysql_fetch_array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13127@lists.php.net to get a copy of this message | ||
hi there,
I have a prob I haven't been able to solve by trawling through php.net and
the web. I have multiple SQL statements that select data from a MySQL
database.
As far as I understand it PHP stores the results as an associative array.
Now I need to sort these results in one big go, in PHP and I tried
array_merge() to merge the multiple associative arrays (the SQL SELECT
results) into one array so I could manipulate it in PHP.
I appear to be able to do it but cannot read data from it. I've tried this..
$results_array = array_merge($array1, $array2);
for ($x = 0; $x < count($results_array); $x++) {
$id = $results_array[$x]["id"];
$type = $results_array[$x]["type"];
$name = $results_array[$x]["name"];
$search_results .= "$name, $type (ID: $id)<br>\n";
}
where in the SQL query three fields are selected, all called 'id', 'type'
and 'name' from the two different tables. Needless to say this doesn't work.
Any ideas, have I done anything obviously wrong?
thanks,
Simon
--------------------------------------------
Studio 24 Ltd | tel. 01223 501 892
3 Willis Road | fax. 0870 063 1216
Cambridge | mob. 07974 074 547
CB1 2AQ | www.studio24.net