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

Link to comment
Share on other sites

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

?>

Link to comment
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;

 

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.