RE: merging arrays from a mysql_fetch_array

From: Date: Thu, 24 Aug 2000 00:36:33 +0000
Subject: RE: merging arrays from a mysql_fetch_array
Groups: php.general 
Request: Send a blank email to php-general+get-13269@lists.php.net to get a copy of this message
---------------------------------------------------------------------------- ----------------- Disclaimer: The information contained in this email is intended only for the use of the person(s) to whom it is addressed and may be confidential or contain legally privileged information. If you are not the intended recipient you are hereby notified that any perusal, use, distribution, copying or disclosure is strictly prohibited. If you have received this email in error please immediately advise us by return email at postmaster@normandy.com.au and delete the email document without making a copy. ---------------------------------------------------------------------------- ----------------- It really depends on the resulting key. you would be much better off with; $results_array = array_merge($array1, $array2); while(list($key,$row) = each($results_array)){ $id = $row["id"]; $type = $row["type"]; $name = $row["name"]; $search_results .= "$name, $type (ID: $id)<br>\n"; } I tend to think the while structure is also a lot more tidy, plus doesnt care what you $key is. Now funnily enough $results_array = $array1 + $array2; could also do what you want but keys from array2 will replace those in array1 and im not sure if this sort of thing is really supported :) mn -----Original Message----- From: Simon R Jones [mailto:simon@studio24.net] Sent: Wednesday, August 23, 2000 6:05 PM To: php-general@lists.php.net Subject: merging arrays from a mysql_fetch_array 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

« previous php.general (#13269) next »