| 9:59 pm on Sep 2, 2004 (gmt 0)|
Id like to query a MySQL database with PHP but tell it to start querying from the last record and go backwards.
I know how to get the last line from a query, but this database may be very large, and the data that is needed will always be newly entered info, thus, at the end.
| 10:02 pm on Sep 2, 2004 (gmt 0)|
In your SQL query, add in an ORDER at the end, and order it by something that you know will make the records be in reverse order (such as an auto incrementing numerical ID or date the record was entered).
select * from mytable where field like '%blah%' order by ID desc limit 0,30
The limit parameter will also help you limit how many rows are returned, saving a bit of resources.
Hope this helps!
| 10:09 pm on Sep 2, 2004 (gmt 0)|
Yes, I have that in my query.
But does that actually search backwards, or does it just return your data in reverse order?
| 10:16 pm on Sep 2, 2004 (gmt 0)|
It returns the data in that particular order.
| 10:23 pm on Sep 2, 2004 (gmt 0)|
If I have a large file, lets say a Gigabyte, and I need to access the last line isnt it better to query backwards since I know the data will be at the end? or is this really a non-issue my Mysql?
| 10:26 pm on Sep 2, 2004 (gmt 0)|
It kind of isn't an issue in MySQL, but a lot of rows in a table can slow performance. You can index fields in MySQL to make your queries run faster. If there is a field you are searching consistently, try indexing it and it will make your queries run faster.