Welcome to WebmasterWorld Guest from 54.145.44.134

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

A Disappearing Syntax Error Message

Hit F5 and the message disappeared

     

adder

8:21 pm on May 20, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

I suspect gremlins. I've got a simplest MySQL query

$toProcess = mysql_query("SELECT * FROM url_list ORDER BY id DESC LIMIT 7 WHERE type='get'");


The first time I ran the test script I got a blank screen.
Then I hit F5 and got a Syntax error message suggesting that I have to consult the manual and check for errors around WHERE type='get'
I hit F5 again and I got a blank screen again.

Unless both the MySQL manual and W3schools tutorial are wrong, there is no syntax error in my query.

Please help!

brotherhood of LAN

8:29 pm on May 20, 2012 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Change it to this

$toProcess = mysql_query("SELECT * FROM url_list ORDER BY id DESC LIMIT 7 WHERE type='get'") or die(mysql_error());

and you'll get a more definitive error message, if you can manage to reproduce it.

adder

9:03 pm on May 20, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Aha, good idea, thank you.

This is the error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE type='get'' at line 1

The funny thing is that it's not the line 1. It should be line 3.

brotherhood of LAN

9:40 pm on May 20, 2012 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I should have read the query more closely rather than the scenario. Your syntax is a little off

SELECT * FROM url_list WHERE type='get' ORDER BY id DESC LIMIT 7

The WHERE part of the query is in the wrong place, the above is the correct place. If you think of the SQL as left to right logic it makes sense that the WHERE statement should be there, as ordering and limiting would be done after the filtering done in the WHERE command.

adder

8:38 pm on May 25, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yes indeed, it makes sense. For some reason I thought that it doesn't matter. Now working perfectly, thank you!