我在购物车中收到错误邮件“警告:mysql_fetch_assoc():提供的参数不是有效的 MySQL 结果资源”,我在邮件“总计:0.00 美元”上只收到此文本,但购物车不是空的
function emailcartview() {
$total=0;
$totalvalue=0;
$str = '';
foreach($_SESSION as $name => $value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price, item_number FROM products WHERE id='.mysql_real_escape_string($id));
$cart = array();
while ($get_row = mysql_fetch_assoc($get)) {
$cart[] = array(
'hsid' => $get_row['id'],
'price' => $get_row['price'],
$price = $get_row['price'],
'itemno' => $get_row['item_number'],
'name' => $get_row['name'],
'value' => $value,
$sub = $value*$cost,
$total += $sub,
$totalvalue = $value,
'realsub' => number_format($sub, 2),
);
}
foreach($cart as $index => $record){
global $emailcart;
$str = "Item: {$record['itemno']} - {$record['name']} | Qty: {$record['value']} | Cost: {$record['price']} x {$record['value']} = {$record['realsub']} <br>";
}
}
}
}
$str = "Total : $".number_format($total, 2);
return $str;
}