Odd problem with do while loop

I have an odd problem with a do-while php loop that I have set up to build a drop down menu using information pulled from a database via mysql.

The drop-down menu code:

<?php while ($row2 = @mysql_fetch_assoc($result2)){ ?> <?php echo $row2['NumberDates']; ?> <?php } ?>

The MYSQL pull:
“SELECT * FROM TransNumberID ORDER BY WeekID DESC”;

Related code to pull:

$result2 = mysql_query($query2);
if (!$result2) {
die('Invalid query: ’ . mysql_error());
} else {
$row2 = @mysql_fetch_assoc($result2);}

Here is the problem. I am pulling 9 records from a database. If I don’t specify a descending order on the pull, all nine dates appear in the dropdown. If I specify a descending order on the database, only 8 appear in the dropdown. The latest record in the database never appears in the dropdown when a descending order is specified, but will appear otherwise. Unfortunately, I need a descending order.

Does anyone know why this is happening?

Hi,

Please check your last record which is not coming in list may be the date field is blank in it or junk value is there and if non of it than please give me your table here so that I can give you the exact query to fetch data in desc order.

I should have posted this yesterday. I fixed it - the problem was mine. I had two fetches running and did not realize it. The first one was not part of the loop, so it only pulled one record out. Most likely it was operating in both directions - ASC and DESC - and I just didn’t realize it.

So the problem, which existed between the keyboard and the seat, has been fixed. Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service