1

我正在处理购物车。我遇到了一个问题,其中 fetch_array 没有从 mysql 数据库中的项目中提取结果。我需要这个来提取当前数量和用户在项目上的注释。然后它将新值添加到旧值并组合注释。目前,只有 $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");
   }
}
4

1 回答 1

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");
    }
}
于 2013-02-03T01:53:31.743 回答