Jump to content

Adding a value from MySQL query array into a PHP array


ben9292

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.