lance Posted July 8, 2003 Share Posted July 8, 2003 Or 10 or whatever number you want to display (not all). I\'m new to all this wonderful PHP MySQL stuff and would like to display a table of the last 20 entries made. To be more specific it\'s a PIREP reporting system for pilots to submit their flight hours, destination, etc... I can\'t display all, but would like to be able to display the last 20 or so pireps in a table. I AM Able to query the database and display ALL records, but that page will be come waaaaaaaaaay to large very fast ;-) Thanks for any help or any links you could provide to tutorials that might help me understand how to do this. Quote Link to comment Share on other sites More sharing options...
effigy Posted July 8, 2003 Share Posted July 8, 2003 use the limit feature at the end of your query. e.g.: select * from table limit 20 Quote Link to comment Share on other sites More sharing options...
dammitjanet Posted July 8, 2003 Share Posted July 8, 2003 just to expand of effigy\'s post you can do this. select count(*) from table; and stick it in a variable called $max ... and subtract 20 from it. then make your query string \"select * from table limit $max,-1\" which should give you the last 20 lines of the table. you may want to stipulate an order by clause on a datetime field or unique incremental to make sure the data is the last 20 entries. Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 9, 2003 Share Posted July 9, 2003 Mysql\'s limit feature is one of the really nice things it offers. That\'s definately the way to go. Hopefully you have a key to the table using auto_increment, or have a timestamp column. Then you would not have to bother with trying to get the count(*) and do a limit count(*)-20, and would instead simply do: SELECT * FROM Table ORDER BY Table_id DESC LIMIT 20; This will display the rows most recent first. May be what you want, and saves an extra query. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.