[英]Converting MySQL to MSSQL in PHP: unidentified index in session
我正在將我的代碼從 PHP、MySQL 轉換為 sqlsrv,出於某種原因,我的“購物車”被稱為身份不明的索引。 知道為什么嗎?
<?php
if ($_SERVER['REQUEST_URI'] != '/index.php?page=cart') {
$sql="SELECT * FROM table WHERE id IN (";
foreach($_SESSION['cart'] as $id => $value) {
$sql.=$id.",";
}
$sql=substr($sql, 0, -1).") ORDER BY name ASC";
@$query= sqlsrv_query($conn, $sql);
$numrows = sqlsrv_num_rows($query);
if($numrows != 0) {
?><h1>Current Order</h1><?php while($row= sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
?>
<p> <?php echo $row['name'] ?> X <b><?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?></b></p>
<?php
}
?>
在<?php
標簽后添加session_start()
session_start();
if ($_SERVER['REQUEST_URI'] != '/index.php?page=cart')
{
$sql="SELECT * FROM table WHERE id IN (";
foreach($_SESSION['cart'] as $id => $value)
{
$sql.=$id.",";
}
它會為你工作,也檢查isset
通過$_SESSION['cart']
然后使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.