Jump to content

[SOLVED] Dropdown from query. Always lists 1 missing.


Greaser9780

Recommended Posts

The following is some of my code for a dropdown box from a query. I tried ORDERing the info many ways. There are 12 names in the table but it always shows 11. What am I missing?

 

<select  name='1name'>

<?php

$sql1=mysql_query("SELECT * FROM draft_teams WHERE teamid > '0' ORDER BY name DESC") or die(mysql_error());

$res1=mysql_fetch_array($sql1);

$rst1=$res1['name'];

while ($res1 = mysql_fetch_array($sql1, MYSQL_ASSOC)){

  echo "<option value='" . $res1['name'] . "'>" . $res1['name'] . "</option>";

}

?>

</select><br>

 

Link to comment
Share on other sites

Try this:

<select  name='1name'>
<?php
$sql1=mysql_query("SELECT * FROM draft_teams WHERE teamid > '0' ORDER BY name DESC") or die(mysql_error());
while ($res1 = mysql_fetch_array($sql1, MYSQL_ASSOC)){
   echo "<option value='" . $res1['name'] . "'>" . $res1['name'] . "</option>";
}
?>
</select>

Link to comment
Share on other sites

You called mysql_fetch_array once before the loop, so one is "missing".

 

Try this:

<select  name='1name'>
<?php
$result1 = mysql_query("SELECT * FROM `draft_teams` WHERE teamid > 0 ORDER BY name DESC") or die(mysql_error());
while ($row = mysql_fetch_assoc($result1))
   echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>";
?>
</select>

 

 

Orio.

Link to comment
Share on other sites

I think I get it. Because I called it outside the while loop already that's why it left one out.

Exactly :)

When one result "missing", in most cases it means you called mysql_fetch_array() before the loop.

 

lol Yesideez, I can't handle your speed!

 

Orio.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.