我当前在购物车上工作。我遇到了一个问题,fetch_array没有从mysql DB中的项目中提取结果。我需要这个来提取当前数量和用户在该项目上的注释。然后,它将新值添加到旧值并组合注释。目前,只有$ newQty& $ newNotes返回一个值,该值来自之前页面上的表单。有什么想法吗?
$item_query = "SELECT COUNT(*) FROM `rel` WHERE `cart_id` = ' " .$cartId. "' && `id_item` = ' " .$item_id. " '";
$item_result = $mysqli->query($item_query) or die($mysqli->error.__LINE__);
if($item_result->num_rows == 1) {
while($getOldItems = $item_result->fetch_array()){
$oldQty = $getOldItems['amount'];
$oldNotes = $getOldItems['notes'];
$newQty = ($oldQty + $item_quantity);
$newNotes = $oldNotes . $item_notes;
print("Old QTY: $oldQty, Old Notes: $oldNotes, New QTY: $newQty, New Notes: $newNotes");
}
}
答案 0 :(得分:1)
$item_query = "SELECT COUNT(*) FROM `rel` WHERE `cart_id` = '" .$cartId. "' && `id_item` = '" .$item_id. "'";
$item_result = $mysqli->query($item_query) or die($mysqli->error.__LINE__);
if($item_result->num_rows == 1) {
$item_query = "SELECT * FROM `rel` WHERE `cart_id` = '" .$cartId. "' && `id_item` = '" .$item_id. "'";
$item_result2 = $mysqli->query($item_query) or die($mysqli->error.__LINE__);
while($getOldItems = $item_result2->fetch_array()){
$oldQty = $getOldItems['amount'];
$oldNotes = $getOldItems['notes'];
$newQty = ($oldQty + $item_quantity);
$newNotes = $oldNotes . $item_notes;
print("Old QTY: $oldQty, Old Notes: $oldNotes, New QTY: $newQty, New Notes: $newNotes");
}
}