homepage Welcome to WebmasterWorld Guest from 54.211.68.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Searching Backwards
Schoolbag

10+ Year Member



 
Msg#: 4949 posted 9:59 pm on Sep 2, 2004 (gmt 0)

Hi,

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.

 

jusdrum

10+ Year Member



 
Msg#: 4949 posted 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).

Example:

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!

Schoolbag

10+ Year Member



 
Msg#: 4949 posted 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?

thanks.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4949 posted 10:16 pm on Sep 2, 2004 (gmt 0)

It returns the data in that particular order.

Schoolbag

10+ Year Member



 
Msg#: 4949 posted 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?

jusdrum

10+ Year Member



 
Msg#: 4949 posted 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved