O/H Michael Kelly ??????:
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 />';
}
?>
I think that the ID_BOARD field should be an integer so you probably you
could leave unquoted (no harm with that). Check in the table what type
is the ID_FIRST_MSG because varchars order quite differently than
intergers. This I suspect this could be the mistake because I think that
you mean to use an integer.
In any case if you don't find what is wrong you can always put query
results in an array and sort them experimenting to see what is causing this.
My setup is as follows:
Windows Vista Business with Service Pack 1
Well you could always use a unix-like operating system but not all of us
are geeks.
Apache 2.2
PHP Version 5.2.6
MySQL 5.1.23-rc-community via TCP/IP
Any help would be greatly appreciated.
These are fresh so you shouldn't be having a problem.
--
Thodoris
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php