Re: SELECT into array of arrays

From: Date: Wed, 03 Dec 2008 08:08:39 +0000
Subject: Re: SELECT into array of arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284040@lists.php.net to get a copy of this message
> How should I proceed? Thanks in advance for any suggestions. Since you are looping through the result already, why not do it this way .. $combinedArray = array(); for ($i=0;$i<count($myArray);$i++) { $sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while ($myrow = mysql_fetch_array($result)) { if (in_array($myrow['study'], $myArray)) $combinedArray[$myrow['study']][] = $myrow['symbol']; } } } You should get an array like this ... array("b2008" => array("A", "B", "C", "D"), "b2005" => array("A", "B", "E"))

« previous php.general (#284040) next »