PDA

View Full Version : Loop through MySQL table data


Ellipsis
10-26-2007, 12:57 AM
Currently I access rows from tbl_cart to see if a product already exists. If it does, it UPDATES the ct_qty. Otherwise, it adds a new product. Now I have different options for color and size I would like to include. So I would like to be able to not only check for matching pd_id and ct_session_id, I would like to check if the color and size matches. This is how my current system is set up:



$sid = session_id();

// check if the product is already
// in cart table for this session
$sql = "SELECT pd_id
FROM tbl_cart
WHERE pd_id = $productId AND ct_session_id = '$sid'";
$result = dbQuery($sql);

if (dbNumRows($result) == 0) {
// put the product in cart table
$sql = "INSERT INTO tbl_cart (pd_id, ct_qty, ct_session_id, item_color, item_size ct_date)
VALUES ($productId, 1, '$sid', '$color', '$size', NOW())";
$result = dbQuery($sql);
} else {
// update product quantity in cart table
$sql = "UPDATE tbl_cart
SET ct_qty = ct_qty + 1
WHERE ct_session_id = '$sid' AND pd_id = $productId";

$result = dbQuery($sql);
}



Any help would be appreciated.

Fumigator
10-26-2007, 02:34 AM
I believe what you want is the "AND" operator. The "AND" operator.