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>

 

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>

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.

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.

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.