Jump to content

latest 9 items .. expert help needed


pouncer

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/45917-latest-9-items-expert-help-needed/
Share on other sites

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;

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;
}

?>

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?

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.