Hey
$sql="SELECT * FROM $tbl_name ORDER BY id DESC"; $result=mysql_query($sql);
How can i make it so only the 5 newest entery's are selected?
$sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 5";
Excerpt from the MySQL Manual :: SELECT Syntax:
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements). ... With one argument, the value specifies the number of rows to return from the beginning of the result set: SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).
...
With one argument, the value specifies the number of rows to return from the beginning of the result set:
SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows
To reiterate, the LIMIT 5 will only select the first five entries as ordered by 'id'. If you have a timestamp column then you can order by that and limit it to 5. That would truly give you what you asked for.