Jump to content

Storing MYSQL results in arrays


kieronjones

Recommended Posts

Hi,

I'm wokring on a little piece of code and really needs some help.

 

Here's the code that I have

$query = "SELECT first_name, last_name, email_address, btnumber, league FROM tb_user WHERE league = $league"; 

			$result = mysql_query($query) or die(mysql_error());


			while($row = mysql_fetch_array($result)){
				echo $row['first_name']. " - ". $row['last_name'];
				echo "<br />";
			}

 

This works fine however what I would like to be able to do is 2 things.  Firstly, store each row of results in individual arrays which I can use later. 

 

I would then like to be able to create a drop down menu, the values being $row['first_name'] & $row['last_name'] from each row of database results eg. So the user can select a specific person from the dropdown menu.

 

Thanks for any guidance and help offered.

 

Kiz

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/207035-storing-mysql-results-in-arrays/
Share on other sites

while($row = mysql_fetch_array($result))
{					
$data_array[] = $row;
}

//now what you can do is use that $data_array where you want in that page
if(count($data_array) > 0)
{
foreach($data_array as $data)
{
	echo $data['col_name1'];
	echo $data['col_name2']; //etc, etc
}
}

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.