這個問題和它的標題可能會作爲一個模糊的問題來看,我很抱歉,如果它確實如此,但我沒有其他方式來問這個問題,因爲我自己很困惑。如何停止產品編號10以在PHP中下推產品編號9?
還好這裏有雲:
我創建了一個網站,該網站所有者可以發佈產品,以及它們在主頁上的圖像!這一點工作正常。
該主頁將只顯示最多10個產品。這一點也適用。
產品按數字存儲在數據庫中。例如:第一個項目/產品保存爲產品編號1,1是其ID,產品編號2是2,3是3,依此類推。 這一點也工作正常,因爲我想它的工作。
這裏的問題:
可以說我已經加入10個產品,這是最大可顯示在主頁德的主頁。產品1至10
當我添加一個新的產品(產品編號11),這個新增加的產品將清除最久產品附加值是產品編號爲1
我不希望這種事情發生。我需要將產品/項目留在隊列中,並像其他產品一樣存儲在數據庫中直到我手動刪除/刪除舊的項目,它將自動替換。
這是我使用的添加產品到數據庫的代碼:
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
$product_name = mysql_real_escape_string($_POST['product_name']);
$link = mysql_real_escape_string($_POST['link']);
$retail = mysql_real_escape_string($_POST['retail']);
$clicks = mysql_real_escape_string($_POST['clicks']);
$price = mysql_real_escape_string($_POST['price']);
$category = mysql_real_escape_string($_POST['category']);
$subcategory = mysql_real_escape_string($_POST['subcategory']);
$details = mysql_real_escape_string($_POST['details']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="index.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO products (product_name, link, retail, clicks, price, details, category, subcategory, date_added)
VALUES('$product_name','$link','$retail','$clicks','$price','$details','$category','$subcategory',now())") or die (mysql_error());
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
header("location: index.php");
exit();
}
?>
任何幫助將是greately很有幫助。即使它把我放在正確的方向。
謝謝
所以只需選擇最近的10個產品...'select ... order by ID DESC limit 10' – 2013-02-27 17:23:41
發佈您的數據庫表模式可能會有所幫助 – Czechnology 2013-02-27 17:25:35
您想更改產品的主頁代碼如何顯示在? – Hast 2013-02-27 17:33:14