Asesha George
Asesha George

Reputation: 2268

how to display selected records in descending order bases on last id MySQL PHP

I am trying to display MySQL database selected records in descending order based on the last id. but it's not working please see the SQL statement below

SELECT * FROM product WHERE catagory='$pro' AND id >($id) LIMIT 6 DESC

I want to show only 6 records at a time.

Upvotes: 0

Views: 36

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133360

add an order by eg:

  SELECT * FROM 
  product WHERE catagory='$pro' AND id >($id) 
  ORDER BY id DESC  LIMIT 6 

but you should not use php var in sql you are at risk for sql injection

take a look at your sql driver for use binding param

Upvotes: 1

Madhu
Madhu

Reputation: 326

SELECT
  *
FROM
  product
WHERE
  catagory = '$pro'
  AND id > ($id)
ORDER BY id desc
LIMIT 6;

Upvotes: 0

Related Questions