[英]Showing newest mysql rows in front end search
Can someone help me show the newest row ids when searching the database. 有人可以帮我在搜索数据库时显示最新的行ID。 Here is my code, limited to showing 100 results, but it shows the oldest rows first.
这是我的代码,仅限于显示100个结果,但它首先显示最旧的行。 I would like to show the newest rows.
我想展示最新的行。 Keep in mind i do not have a time stamp.
请记住,我没有时间戳。
$query_str = "SELECT * FROM puppy_data
WHERE (`breed` LIKE '%".$query."%')
OR (`sex` LIKE '%".$query."%')
LIMIT 100 " ;
Try this (assuming you have a row called 'id'). 试试这个(假设你有一行名为'id')。
$query_str = "SELECT * FROM puppy_data
WHERE (breed LIKE '%".$query."%')
OR (sex LIKE '%".$query."%')
ORDER BY id SORT DESC LIMIT 100" ;
Use the ORDER BY <column(s)> DESC
clause to sort by one or more columns in descending order. 使用
ORDER BY <column(s)> DESC
子句按降序排列一列或多列。 This works if you have an auto incrementing ID column, or a DateTime created_at column. 如果您有自动递增ID列或DateTime created_at列,则此方法有效。 Remember that ideally the column you are ordering by should be an indexed one.
请记住,理想情况下,您订购的列应该是索引列。
SELECT * FROM puppy_data
WHERE (breed LIKE '%".$query."%')
OR (sex LIKE '%".$query."%')
ORDER BY id DESC
LIMIT 100
https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html https://dev.mysql.com/doc/refman/5.7/en/sorting-rows.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.