newstudents

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About newstudents

  • Rank
    Newbie
  1. i have got it..thanks sir.
  2. in this part $product->execute();- i got this error. Notice: Undefined variable: product in C:\xampp\htdocs\hcc\cart.php on line 375 Fatal error: Uncaught Error: Call to a member function execute() on null in C:\xampp\htdocs\hcc\cart.php:375 Stack trace: #0 C:\xampp\htdocs\hcc\cart.php(306): cart_display() #1 {main} thrown in C:\xampp\htdocs\hcc\cart.php on line 375
  3. 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; ?>
  4. sorry i'm new to this. as i know the code is get the sum for product_price based on product_id.correct me if i'm wrong
  5. there is no output for that code....the code not capture the price
  6. ya...product_id is unique. 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
  7. this code $get_sum = $db->prepare('SELECT SUM(product_price) AS total FROM product WHERE product_id = ?'); $get_sum->execute(array($product_id)); if($data = $get_sum->fetch(PDO::FETCH_ASSOC)) { $total = $data['total']; }
  8. i have try the code..but the output still the same. only get latest price.hope you can help me
  9. I'm trying to get total price from cart table. The product_price in other table which is product. I'm only getting the latest price not the total price. Thanks 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; } } I'm trying to get total price from cart table. The product_price in other table which is product. I'm only getting the latest price not the total price. Thanks