Forum Moderators: mack

Message Too Old, No Replies

select list help

I am trying to populate a dropdown list with mysql

         

CriamP

3:10 pm on Feb 24, 2004 (gmt 0)

10+ Year Member



I am trying to populate a dropdown list with mysql - the list is displaying fine but there is a extra <option> that is displaying an empty field - can anyone shed some light on this? i have checked the database, there are no empty records.
thankyou for any help.

the code

<select name="people">
<option value="">> select the person</option>
<?php
do {
?>
<option value="<?php echo $row['id']?>">> <?php echo $row['firstname']?> <?php echo $row['lastname']?></option>
<?php
} while ($row = mysql_fetch_assoc($people));
?>
</select>

the html produced

<select name="people">
<option value="">> select the person</option>
<option value="">> </option>
<option value="6">> tom smith</option>
<option value="4">> james smith</option>
<option value="1">> john smith</option>
<option value="3">> joe smith</option>
<option value="2">> helen smith</option>
<option value="5">> tom jones</option>
</select>

Strange

9:22 pm on Feb 24, 2004 (gmt 0)

10+ Year Member



Hi CriamP.. Welcome to Webmaster World!

Have you tried using a different loop? The extra <option> in your results may be because the statement is executed one time before your test statement.

CriamP

9:22 am on Feb 25, 2004 (gmt 0)

10+ Year Member



Thankyou for help - i used the while loop bellow which has removed the space - thanks again.

<?php
while ($row = mysql_fetch_assoc($person))
{
?>