gpt4 book ai didi

php - PHP 主页上的新项目

转载 作者:行者123 更新时间:2023-11-30 00:15:55 25 4
gpt4 key购买 nike

我在主页上显示了最新的项目,直到今天一切都还好,我注意到我今天添加的项目没有出现在我的主页上,我不知道为什么这是我的代码

<?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();
?>

最佳答案

将限制更改为您想要显示的数量:

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

注意:如果存储的唯一内容是没有时间的日期,那么如果您想要添加它们的实际顺序,则还需要按其他内容(例如 id)进行排序:

SELECT * FROM products ORDER BY date_added DESC, id DESC LIMIT 15

关于php - PHP 主页上的新项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23662765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com