When I add ORDER BY, it gives me an error.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

When I add ORDER BY, it gives me an error.

Post by Skara »

All it says is a syntax error.

Code: Select all

SELECT * FROM books_list WHERE author='{$_GETї'author']}' ORDER BY order
Don't get it, as I have basically the same thing in another one and it works fine:

Code: Select all

SELECT * FROM books_authors ORDER BY name
I know it's something stupid. :P What am I doing wrong?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Show us the entire line of PHP code. Then we can help you.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

I think you will find that order is a reserved word.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

As wayne says, order is a reserved word

You should change the name of your "order" column to "order_number" or something
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

... or wrap it in backticks:

Code: Select all

... ORDER BY `order`
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

aHAH!! Well, didn't even think about that for some reason! ^^; Probably because I'm so bashed from finals week. :P
Post Reply