Page 1 of 1

Problem with dropdown boxes in PHP

Posted: Tue Jun 28, 2005 11:26 pm
by CincoPistolero
I have a drop down box that does a SELECT *, but it doesn't display the first record. Then it marks the record it doesn't show as the record selected, no matter what I select. below is some of my code. Can anyone help me solve this riddle.

Here is the SELECT call.

Code: Select all

$queryplayers = " SELECT * FROM `players` ORDER BY `last_name` ASC";
$resultplayers = mysql_query($queryplayers) or die ("Error in query: $queryplayers. " . mysql_error());

$row3 = mysql_fetch_array($resultplayers);
extract($row3);
Here is the code for the drop down.

Code: Select all

<select name="player_id" height=20 multiple>
              <option selected>---- Please Select a Player ----</option><?php 
              while ( $rowplayers= mysql_fetch_array($resultplayers)){extract($rowplayers);
              echo "
              <option value='$player_id'>$last_name, $first_name</option>"
              ;}?>
             </select>
Here is what I am trying to send to the db table and as you can see, without even selecting anything, it has selected the row that does not show up in the drop down.

Code: Select all

<input type="hidden" name="player_id" value="00178">
<input type="hidden" name="first_name" value="Rohan">
<input type="hidden" name="last_name" value="Allwood">
<input type="hidden" name="home_town" value="Pinehurst, North Carolina">

Posted: Wed Jun 29, 2005 2:49 am
by djot
-
I don't know why everyone uses/may use while() for looping through records. I also always loose arrays' first value - seems like some people have more magic hands while typing the word "while" ...

Instead I loop through the results with a foreach() - this way I do not loose the first value.

djot
-