Problem with dropdown boxes in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CincoPistolero
Forum Newbie
Posts: 6
Joined: Thu Jun 23, 2005 4:30 pm

Problem with dropdown boxes in PHP

Post 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">
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

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