Jump to content

linda111

New Members
  • Posts

    3
  • Joined

  • Last visited

linda111's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i try to do while loop using fetchAll...but only 1st item will be the output. thanks for the help <?php function cart_display(){ global $db; $ip=getIp(); $query = $db->prepare(" SELECT * FROM cart where ip_add = '$ip'"); $query->setFetchMode(PDO::FETCH_ASSOC); $query->execute(); while ($row=$query->fetch()): $product_id=$row['p_id']; $query = $db->prepare("SELECT * FROM product where product_id = :product_id"); $query->bindParam(':product_id', $product_id); //$query->setFetchMode(PDO::FETCH_ASSOC); $rows = $query->fetchAll(PDO::FETCH_ASSOC); $query->execute(); $row=$query->fetch(); echo" <tr> <td><input type = 'checkbox' name='remove[]' value='<?php echo $product_id?>'/> </td> <td>".$row['product_name']." <br><img src='admin/product_images/".$row['product_image']."' width='80' height='80'/></td> <td><input type='text' name='qty' value='".$row['qty']."'/></td> <td>".$row['product_price']."</td> </tr> "; endwhile; ?>
  2. yes i know about session. i use ip in cart function as user not confirm yet to buy the product. as they want make a payment then only need to login to paypal accout. i have try joins but there is no output for total price. function total_price() { global $db; $ip = getIp(); $query = $db->prepare(' SELECT SUM(p.product_price * c.quantity) AS total FROM cart AS c JOIN product AS p ON p.product_id = c.p_id WHERE c.ip_add = :ip '); $query->bindParam(':ip', $ip); $query->execute(); $row = $query->fetch(PDO::FETCH_ASSOC); if($row) { $total = (float) $row['total']; } else { $total = 0; } return $total; }
  3. currently i have develop e-commerce website for my uni project. this code are for total price in cart part. in cart table there is 3 column which is p _id, ip_add and qty. in table product there is 6 column and on of that are product_price. so i want to get sum for total price for the item that user want to buy. the total price should get based on the total product that user add to cart. so the price should be get by product_id function total_price () { $total = 0; global $db; $ip = getIp(); $sql = $db->query("SELECT * from cart WHERE ip_add='$ip'"); $row = $query->fetch(PDO::FETCH_ASSOC); if ($row) { } $no=$sql->rowCount(); // number of rows affected by the last SQL statement if ($no == 0) { echo ""; } else { foreach($sql as $row) $product_id = $row["p_id"]; $sql = $db->query("SELECT product_price from product WHERE product_id='$product_id'"); $no=$sql->rowCount(); // number of rows affected by the last SQL statement if ($no == 0) { echo ""; } else { foreach($sql as $row) $product_price = array($row["product_price"]); $values = array_sum($product_price ); $total += $values; } } echo "RM" . $total; } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.