pouncer Posted April 6, 2007 Share Posted April 6, 2007 I'm going to create a table in my database called 'latest_items' which should store the latest 9 items (which my users upload etc) but how would i display the latest 9 items. and what if the table already contains 9 records.. and a user uploads a new item, how would i change the table i hope someone can help me out! Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 6, 2007 Share Posted April 6, 2007 Why do you need to store them separately? If you have an incrementing ID column or a date stamp for each upload, you could simply query your full items table for the last 9 items instead of trying to store them separately: SELECT * FROM item_table ORDER BY id DESC LIMIT 9; Quote Link to comment Share on other sites More sharing options...
Tandem Posted April 6, 2007 Share Posted April 6, 2007 To display what is in your database table you can use a query and a query result, and then a loop. Example <?php $get_items = mysql_query("SELECT * FROM latest_items"); $items_num = mysql_num_rows($get_items); for ($i = 0 ; $i < $items_num ; $i++) { $item = mysql_result($get_items, $i); echo $item; } ?> Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2007 Author Share Posted April 6, 2007 Why do you need to store them separately? If you have an incrementing ID column or a date stamp for each upload, you could simply query your full items table for the last 9 items instead of trying to store them separately: SELECT * FROM item_table ORDER BY id DESC LIMIT 9; so say my item_table has 70 items, will that return the latest 9 items? ie. records 61,62,63,64,65,67,68,69,70? Quote Link to comment Share on other sites More sharing options...
per1os Posted April 6, 2007 Share Posted April 6, 2007 Try it out and see what happens. That is the only way you will ever learn. Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 6, 2007 Share Posted April 6, 2007 so say my item_table has 70 items, will that return the latest 9 items? ie. records 61,62,63,64,65,67,68,69,70? As long as your items are incremented as they are entered and your most recent one is #70, yes. Keep in mind that it is ordering descending, so it would be 70-62 (not 61 since you asked for 9 items). Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2007 Author Share Posted April 6, 2007 yep, it works perfectly.. thanks! you saved me having creating the other table and stuff! 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.