简体   繁体   中英

How to remove past data from your search results and only display the current one

Here is the code I wrote in the $sql variable in my includes file:

SELECT 
  itemName, itemRate, itemStatus, itemTrend 
FROM 
  items 
WHERE 
  itemName LIKE '%$search%' 
ORDER BY 
  rowID DESC

and here is what the results look like:

在此处输入图片说明

I get both past data and current data. I only need to display the current data. Thanks if you can help!

What do you mean by past data and current data? Is there a date column so we can say it's new data?

If you want to get the last item only, then this will do the trick:

SELECT itemName, itemRate, itemStatus, itemTrend FROM items WHERE itemName LIKE '%$search%' ORDER BY rowID DESC LIMIT 1

SELECT itemName, itemRate, itemStatus, itemTrend FROM items WHERE itemName LIKE '%$search%' GROUP BY itemName ORDER BY rowID DESC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM