kieronjones Posted July 7, 2010 Share Posted July 7, 2010 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 More sharing options...
phpology Posted July 7, 2010 Share Posted July 7, 2010 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 } } Link to comment https://forums.phpfreaks.com/topic/207035-storing-mysql-results-in-arrays/#findComment-1082580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.