Jump to content

[SOLVED] mysql_fetch_array into an array to use more than once


immanuelx2

Recommended Posts

I understand the easy way to fetch an array is to use a while loop ex:

 

while ($row = mysql_fetch_array($query))

 

However, if I want to use that same array more than once, I should dump it into a separate array like so (correct?):

 

$tables = array(); 
$query = mysql_query("...") or die(mysql_error());
    
while ($row = mysql_fetch_array($query)) 
$tables[] = $row[0];

 

That works, however, later down the line when I use the foreach ($tables as $key => $value) loop to populate a select form element, it only uses it's numerical index instead of the index assigned by the query. My question is, how do I maintain the index from the query? (for example $row['id'] or $row['name'] instead of $row[0])

 

Thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.