Jump to content

Drop Dialogue Box - Displays only the first element of the array twice


darkenroyce

Recommended Posts

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.

 

<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>

 

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.