Jump to content

[SOLVED] Dynamic drop down menu not showing first record


Eiolon

Recommended Posts

It gives me a list of the users except the first record in the table.

 

I tried querying a different table and get the same result.

 

Thanks for your help!

 

 


$query_users = "SELECT id, username FROM users";
$users = mysql_query($query_users) OR die ('Cannot retrieve a list of users.');
$row_users = mysql_fetch_array($users);

 

 


<select name="user">
  <?php
    while($row_users = mysql_fetch_array($users)) {
      print '<option value="' . $row_users['id'] . '">' . $row_users['username'] . '</option>';
    }
  ?>
</select>

Try this:

 

<?php
$q = mysql_query("SELECT * FROM `users`") or die(mysql_error());
?>
<select name="user">
<?
    while ($r = mysql_fetch_array($q)) {
        echo "<option value=\"" . $r['id'] . "\">" . $r['username'] . "</option>";
    }
?>

Its cuz u use mysql_fetch_array in and before the loop.

 

remove it from before the loop. otherwise the first record is always lost

 

$query_users = "SELECT id, username FROM users";
$users = mysql_query($query_users) OR die ('Cannot retrieve a list of users.');
//$row_users = mysql_fetch_array($users);

 

 


<select name="user">
  <?php
    while($row_users = mysql_fetch_array($users)) {
      print '<option value="' . $row_users['id'] . '">' . $row_users['username'] . '</option>';
    }
  ?>
</select>

 

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.