我想做一個會話存儲,然後顯示用戶看到的最後5個產品...但不適合工作php session只能存儲和顯示最近的5個視圖產品
首先存儲相同ID產品,如果我referesh,我想只存儲不同的ID(產品) 2.其次是不顯示我超過1行(1查詢),即使我將有更多的ID商店(不同的產品看到像用戶ID: 3,5,5,6,2)只顯示我在這種情況下的最後一個ID商店 2 ....我想顯示所有的查詢..
。
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
$_SESSION['lastViewProducts'][] = $id;
if(count ($_SESSION['lastViewProducts']) > 5){
array_shift($_SESSION['lastViewProducts']);
}
foreach($_SESSION['lastViewProducts'] as $keyLASTview=>$valueLASTview) {
$stmtLastVIEW = $con->prepare('SELECT id, product_name, price, details, category, subcategory, size, date_added, image, brand_name, product_color, vizualizari FROM products WHERE id=?');
$stmtLastVIEW->bind_param('i', $valueLASTview);
$stmtLastVIEW->execute();
$stmtLastVIEW->bind_result($idSelectDetalii, $produsNumeDetalii, $priceDetalii, $produsDetalii, $produsCategory, $produsSubcategory, $produsSize, $produsDate_added, $imageLocationDetalii, $brandProdusSelectat, $produsColor, $produsVizualizari);
$lastVIEWproduct = '';
while ($stmtLastVIEW->fetch()) {
$lastVIEWproduct .='titlu: '.$idSelectDetalii.' <img src="'.$imageLocationDetalii.'" class="img-responsive">';
}
$stmtLastVIEW->free_result();
}
}
我真的卡住了...我無法找出解決這個問題,也許其他變種? 另外3.第三如果用戶在同一頁上的products.php?id = 3和id = 3它存儲在會話中我不想顯示這個... WHERE id=?(for the showing last 5 products views) and id is not (the $id)?
如何編寫mysql select語句和where條款?如果我想也否定
你需要刪除此行'$ lastVIEWproduct = '';' – cmorrissey
ü需要'$ stmtLastVIEW->使用fetchall()',而不是'$ stmtLastVIEW->取()因爲'fetch()'只給出1個結果,'fetchAll()'給出一個包含所有結果的數組。 – Mario
現在給我'致命錯誤:調用未定義的方法mysqli_stmt :: fetchAll()' – Alcatraz007