0

Inverse PHP mysql_fetch_array

I get last 4 row from database, but I want order these 4 rows in inverse

mysql_query("SELECT * FROM `table` ORDER BY `id` DESC LIMIT 4");

How can I do this?

1
  • mysql_query should not be used in new applications. It's a deprecated interface that's being removed from future versions of PHP. A modern replacement like PDO is not hard to learn and is a lot easier to use correctly. Commented Nov 29, 2013 at 19:17

1 Answer 1

4
mysql_query("SELECT * FROM (SELECT * FROM table ORDER BY id DESC LIMIT 4) t ORDER BY id ASC");

i Think this should do

Sign up to request clarification or add additional context in comments.

4 Comments

I think the OP wants the last 4 as he already has, but wants them ordered ASC instead of DESC. This returns an entirely different rowset.
please do not use mysql_*
Thx Bhadra, why use t before ORDER ?
You have to assign a variable to the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.