Wrong results with ORDER BY DESC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey all. I installed Apache and PHP onto my computer to use for testing about six days ago, and have had MySQL installed for a few weeks before. It all works fine, except for certain queries PHP gets very odd and inconsistent results back.

Here's an example. This query, in both PHP and through the MySQL Query Browser:

SELECT ID_FIRST_MSG FROM smf_topics WHERE ID_BOARD = 51 ORDER BY ID_FIRST_MSG

Will work fine and return a 10-result set of the proper IDs from the smf_topics table sorted correctly. However, this query, different only by the addition of DESC:

SELECT ID_FIRST_MSG FROM smf_topics WHERE ID_BOARD = 51 ORDER BY ID_FIRST_MSG DESC

Will work in the Query Browser fine, but not in PHP. When run from PHP, it will return a 10-result set of an ID from other boards (same table, different ID_BOARD values). All 10 rows will be the same ID, and periodically the ID that is returned changes; sometimes it changes as soon as the page is refreshed, sometimes it only changes after waiting a bit, but there's no pattern I can see here.

Here's the PHP code I'm using to test it:

<?php
mysql_connect('localhost','charas_forum2','********');
mysql_select_db('charas_forum2');
$request = mysql_query("SELECT ID_FIRST_MSG FROM smf_topics WHERE ID_BOARD = '51' ORDER BY ID_FIRST_MSG DESC");
while ($row = mysql_fetch_assoc($request)) {
	echo $row['ID_FIRST_MSG'], '<br />';
}
?>

My setup is as follows:

Windows Vista Business with Service Pack 1
Apache 2.2
PHP Version 5.2.6
MySQL 5.1.23-rc-community via TCP/IP

Any help would be greatly appreciated.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux