SELECT into array of arrays

From: Date: Wed, 03 Dec 2008 07:05:45 +0000
Subject: SELECT into array of arrays
Groups: php.general 
Request: Send a blank email to php-general+get-284035@lists.php.net to get a copy of this message
Dear all, I have a MySQL table 'test' which includes two columns: 'study' and 'symbol': study symbol a2008 A a2008 B a2008 C a2008 D b2005 A b2005 B b2005 E Using POST variable I passed 'study' values into $myArray: // $myArray is variable length; used only two values in example $myArray = array("a2008","b2005"); Then I try to produce the following structure (array of arrays): $combinedArray = array(array('A','B','C','D'),array('A','B','E')); Below is my php script. In the present solution the $combinedArray includes only 'symbol' values for last iteration (where $myArray = "b2005"). How should I proceed? Thanks in advance for any suggestions. Best, Andrej $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)) {
        $combinedArray[] = $myrow['symbol'];
    }
} }

« previous php.general (#284035) next »