Question

I have most recent items displayed on home page and weverythnig was ok till today, I've noticed that the items I've added today didnt appear on my home page and I dont know why here is my code

<?php // Run a select query to get my letest 6 items
// Connect to the MySQL database  
session_start();

include "storescripts/connect_to_mysql.php"; 
$dynamicList = "";
$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"];
    $product_name = $row["product_name"];
    $price = $row["price"];
    $date_added = strftime("%b %d, %Y",     strtotime($row["date_added"]));
    $dynamicList .= ' <div id="test"><div id="wrap" align="center"><div id="columns" class="columns_3"><figure><a class="button" href="product.php?id=' . $id . '"><img class="img" style="border:#666 0px solid ;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '"   border="1" /></a><div class="new_name">' . $product_name . '<br /></div> <div class="new_price">  £' . $price . '<br /></div><div  class="new_buy"><a href="product.php?id=' . $id . '"><img src="style/buy.png" /></a></figure></div></div></div>';
  }  else {
      $dynamicList = "We have no products listed in our store yet";
  }
  mysql_close();
?>
Était-ce utile?

La solution

Change the limit to however many you want to display:

$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");

Note: If the only thing being stored is the date with no time then you will need to also order by something else, like id, if you want the actual order they were added:

SELECT * FROM products ORDER BY date_added DESC, id DESC LIMIT 15
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top