Problem with ORDER BY col_name LIMIT 0,15

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
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Problem with ORDER BY col_name LIMIT 0,15

Post by phice »

So I've been working on this database, blah blah.

$start_pos = 0, $num_links = 15, $order_by = "added"

My SQL:

Code: Select all

SELECT * FROM `aref_users` LIMIT $start_pos,$num_links ORDER BY $order_by
"added" is a column name.

Error: "You have an error in your SQL syntax near ' ORDER BY ' at line 1"

When I switch the "LIMIT $start_pos,$num_links" and the "ORDER BY $order_by", I get the error: "You have an error in your SQL syntax near 'LIMIT ,' at line 1"

Any help?
Image Image
nieve
Forum Newbie
Posts: 11
Joined: Tue Dec 03, 2002 10:26 pm

Post by nieve »

try this
SELECT * FROM `aref_users` ORDER BY $order_by LIMIT $start_pos,$num_links
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

bah. I had all of the tags set inside a while(), and i didn't have that query inside. Weird.
Image Image
Post Reply