I know this involves either loops or the LIMIT function in mysql..
If i have so many rows in a table... how do i make it display the last 5 on a page (like a news page)
so if there are 11 total items, it will show 7-11 if there are 20 it will show 16-20 etc...
All my items are organized by ID which is incremented each new entry...
SELECT * FROM table ORDER BY id DESC LIMIT 0,5
Simply order them by DESCending order rather than ASCending order. This'll be backwards, though.
alright so i have
but how do i show the contents on a page?
My columns are: ID, Date, Title, News
say i wanted to show the Date, Title, and News for each last 5 of the items.
then run the result of the query in say, a loop with mysql_fetch_array()
e.g.
$query = mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 0,5"); while ($row = mysql_fetch_array($query)) { echo $row['id'] . '<br>'; }