I've only been studying PHP for a week now and have come across this problem which I'm sure there is a simple answer to, but I just can't figure it out and would appreciate some help. I've spent far too long on this minor issue already!
I have a table which contains a list of products, in this case books, which stores the date when each new item is added.
I have a query that then searches through this table and extracts the 6 most recent additions.
Here is the code I have so far:
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$title = $row["title"];
$author = $row["author"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamiclist .= //My table showing the products
}
} else {
$dynamicList = "There are currently no Books listed in this store";
}
This works well when I need to display the 5 most recent products in a normal table fashion, one below another, on the page.
However, I want to display the products in a more personalised order. For example display the newest item in one section of the page and 3rd newest in another.
What is the best way to select an individual row from a query? To extract the details of the 2nd newest item to display in the header, for example.
Thanks for your help.