1. How do I select the last 20 rows of a table in my database? 2. Is there anyway in MySQL or PHP to only query a database if the data in a table has changed? Thanks.
1. SELECT columns FROM my_table ORDER BY id DESC LIMIT 20; If you have a auto-increment or other sequential id column or a datetime/timestamp column, you would use that column in the order by. 2. You should use caching to prevent the database from performing a full query every time. http://www.mysqlperformanceblog.com/2006/07/27/mysql-query-cache/ If you are using php, you can also use a front-end caching mechanism like apc which can completely eliminate successive-loads on the database.
I'm trying to get question 1. to work but it isn't working (It only outputs 1 row) This what my order by statement looks like. I'm trying to get 10 of the most recent rows. ORDER BY STR_TO_DATE(`date`, "%m/%d/%Y") DESC, `time` DESC LIMIT 10 Code (markup): Why is it not working? Thanks. Never Mind I got it.