homepage Welcome to WebmasterWorld Guest from 54.211.100.183
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
A Disappearing Syntax Error Message
Hit F5 and the message disappeared
adder

5+ Year Member



 
Msg#: 4455663 posted 8:21 pm on May 20, 2012 (gmt 0)

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

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



 
Msg#: 4455663 posted 8:29 pm on May 20, 2012 (gmt 0)

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

5+ Year Member



 
Msg#: 4455663 posted 9:03 pm on May 20, 2012 (gmt 0)

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

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



 
Msg#: 4455663 posted 9:40 pm on May 20, 2012 (gmt 0)

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

5+ Year Member



 
Msg#: 4455663 posted 8:38 pm on May 25, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved