darkenroyce Posted March 29, 2008 Share Posted March 29, 2008 Hi Guys I am creating a sports database and one of the features involves create drop down dialogue boxes that retrieve data from MySQL tables and provides them as <option> within <select></select>. I am using PHP for this and I'm fairly new at the programming language. I have got the dialogue to work with respect to retrieving the data from MySQL table but it only displays the data from first row/first column of the table twice. I want the foreach loop to iterate down the rows of the first column until it reaches the end of these rows in the MySQL table. Below is the code I used to do it. Please help me to find where I went wrong: <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT player_name FROM table1"; $query = mysql_query($state, $conn); $queryColumn = mysql_fetch_array($query); $aData = $queryColumn; foreach( $aData as $test ){ echo '<option value="' . $aData . '">' . $test . '</option>'; } ?> </select></td> Thanks for your help much appreciated! I've been stuck on this for a while now. Link to comment https://forums.phpfreaks.com/topic/98446-drop-dialogue-box-displays-only-the-first-element-of-the-array-twice/ Share on other sites More sharing options...
metrostars Posted March 29, 2008 Share Posted March 29, 2008 <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT player_name FROM table1"; $query = mysql_query($state, $conn); while( $test = mysql_fetch_array($query); ){ echo '<option value="' . $test['player_name'] . '">' . $test[] . '</option>'; } ?> </select></td> Link to comment https://forums.phpfreaks.com/topic/98446-drop-dialogue-box-displays-only-the-first-element-of-the-array-twice/#findComment-503870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.