Jump to content

Help with ORDER BY function..


virtuexru

Recommended Posts

OK.. so I have this and it works:

[quote]
$query  = "SELECT title, category, salary, location, number FROM joborder WHERE category='Development' LIMIT 3";
$result = mysql_query($query);
while(list($title,$category,$salary,$location,$number) = mysql_fetch_row($result))
[/quote]

But this won't work:

[quote]
$query  = "SELECT title, category, salary, location, number FROM joborder ORDER BY number ASC WHERE category='Development' LIMIT 3";
$result = mysql_query($query);
while(list($title,$category,$salary,$location,$number) = mysql_fetch_row($result))
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/27341-help-with-order-by-function/
Share on other sites

Its because you have ASC after number before the WHERE clause, ASC should appear at the end of the sql statement.

And just so your wondering why no one else has replied to your message its because you didnt really tell anyone why it wasn't working, I on the other hand am just guessing that this is the cause of your problem.
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /**/**/**/**/index.php on line 141

$query  = "SELECT title, category, salary, location, number FROM joborder ORDER BY number WHERE category='Development' LIMIT 3 ASC";

$result = mysql_query($query);
while(list($title,$category,$salary,$location,$number) = mysql_fetch_row($result))
ORDER BY and LIMIT should always be in the end of your query

ex
[code=php:0]SELECT title, category, salary, location, number FROM joborder WHERE category='Development' ORDER BY number ASC LIMIT 3[/code]


Your query can also be written like this:

ex
[code=php:0]SELECT * FROM joborder WHERE category='Development' ORDER BY number LIMIT 3[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.