ben9292 Posted November 26, 2010 Share Posted November 26, 2010 So I'm querying my database to add the results (mapID's) into a PHP array. The MySQL query I used in the below code would usually return 10 values (only 10 mapID's in the database) while($data = mysql_fetch_array(mysql_query("SELECT mapID FROM maps"))){ $sqlsearchdata[] = $data['mapID']; } Instead the page takes ages to load then gives this error: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes) It says the error begins on the first line of the above code. I'm assuming this is not the right way to add the value from the MySQL array into a normal PHP array. Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/219876-adding-a-value-from-mysql-query-array-into-a-php-array/ Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 How large are these fields you're trying to store in the array? Link to comment https://forums.phpfreaks.com/topic/219876-adding-a-value-from-mysql-query-array-into-a-php-array/#findComment-1139814 Share on other sites More sharing options...
ben9292 Posted November 26, 2010 Author Share Posted November 26, 2010 TINYINT[2] the mapID's are just 1-2 digit integers Link to comment https://forums.phpfreaks.com/topic/219876-adding-a-value-from-mysql-query-array-into-a-php-array/#findComment-1139817 Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 Just tested it locally, and building the whole query in the while() loop is cratering it. This should run fine $query = "SELECT mapID FROM maps"; $result = mysql_query( $query ) or die(mysql_error()); while( $array = mysql_fetch_assoc($result) ){ $sqlsearchdata[] = $array['mapID']; } Link to comment https://forums.phpfreaks.com/topic/219876-adding-a-value-from-mysql-query-array-into-a-php-array/#findComment-1139819 Share on other sites More sharing options...
ben9292 Posted November 26, 2010 Author Share Posted November 26, 2010 ah ok... didn't think of that. Thank you very much Link to comment https://forums.phpfreaks.com/topic/219876-adding-a-value-from-mysql-query-array-into-a-php-array/#findComment-1139820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.