Categories

"; if(mysqli_num_rows($run_query) > 0){ $i=1; while($row = mysqli_fetch_array($run_query)){ $cid = $row["cat_id"]; $cat_name = $row["cat_title"]; $sql = "SELECT COUNT(*) AS count_items FROM products WHERE product_cat=$i"; $query = mysqli_query($con,$sql); $row = mysqli_fetch_array($query); $count=$row["count_items"]; $i++; echo " "; } echo "
"; } } if(isset($_POST["brand"])){ $brand_query = "SELECT * FROM brands"; $run_query = mysqli_query($con,$brand_query); echo "

Brand

"; if(mysqli_num_rows($run_query) > 0){ $i=1; while($row = mysqli_fetch_array($run_query)){ $bid = $row["brand_id"]; $brand_name = $row["brand_title"]; $sql = "SELECT COUNT(*) AS count_items FROM products WHERE product_brand=$i"; $query = mysqli_query($con,$sql); $row = mysqli_fetch_array($query); $count=$row["count_items"]; $i++; echo " "; } echo "
"; } } if(isset($_POST["page"])){ $cid = $_POST["cid"]; $sql = "SELECT * FROM products Where product_cat='$cid'"; $run_query = mysqli_query($con,$sql); $count = mysqli_num_rows($run_query); $pageno = ceil($count/9); for($i=1;$i<=$pageno;$i++){ echo "
  • $i
  • "; } } if(isset($_POST["getProduct"])){ $limit = 9; if(isset($_POST["setPage"])){ $pageno = $_POST["pageNumber"]; $start = ($pageno * $limit) - $limit; }else{ $start = 0; } if(isset($_POST["cid"])){ $cat_id = $_POST["cid"]; }else{ $cat_id = $_POST["cat_id"]; } $product_query = "SELECT * FROM products,categories WHERE product_cat = '$cat_id' AND product_cat=cat_id LIMIT $start,$limit"; $run_query = mysqli_query($con,$product_query); if(mysqli_num_rows($run_query) > 0){ while($row = mysqli_fetch_array($run_query)){ $pro_id = $row['product_id']; $pro_cat = $row['product_cat']; $pro_brand = $row['product_brand']; $pro_title = $row['product_title']; $pro_price = $row['product_price']; $pro_image = $row['product_image']; $cat_name = $row["cat_title"]; echo "

    $cat_name

    $pro_title

    $pro_price$990.00

    "; $rating_query = "SELECT ROUND(AVG(rating),1) AS avg_rating FROM reviews WHERE product_id='$pro_id '"; $run_review_query = mysqli_query($con,$rating_query); $review_row = mysqli_fetch_array($run_review_query); if($review_row > 0){ $avg_count=$review_row["avg_rating"]; $i=1; while($i <= round($avg_count ?? 0)){ $i++; echo' '; } $i=1; while($i <= 5-round($avg_count ?? 0)){ $i++; echo' '; } } echo "
    "; } } } if(isset($_POST["get_seleted_Category"]) || isset($_POST["selectBrand"]) || isset($_POST["search"])){ if(isset($_POST["get_seleted_Category"])){ $id = $_POST["cat_id"]; $sql = "SELECT * FROM products,categories WHERE product_cat = '$id' AND product_cat=cat_id " ; }else if(isset($_POST["selectBrand"])){ $id = $_POST["brand_id"]; $sql = "SELECT * FROM products,categories WHERE product_brand = '$id' AND product_cat=cat_id"; }else { $keyword = $_POST["keyword"]; $sql = "SELECT * FROM products,categories WHERE product_cat=cat_id AND product_keywords LIKE '%$keyword%'"; } $run_query = mysqli_query($con,$sql); while($row=mysqli_fetch_array($run_query)){ $pro_id = $row['product_id']; $pro_cat = $row['product_cat']; $pro_brand = $row['product_brand']; $pro_title = $row['product_title']; $pro_price = $row['product_price']; $pro_image = $row['product_image']; $cat_name = $row["cat_title"]; echo "

    $cat_name

    $pro_title

    $pro_price$990.00

    "; $rating_query = "SELECT ROUND(AVG(rating),1) AS avg_rating FROM reviews WHERE product_id='$pro_id '"; $run_review_query = mysqli_query($con,$rating_query); $review_row = mysqli_fetch_array($run_review_query); if($review_row > 0){ $avg_count=$review_row["avg_rating"]; $i=1; while($i <= round($avg_count ?? 0)){ $i++; echo' '; } $i=1; while($i <= 5-round($avg_count ?? 0)){ $i++; echo' '; } } echo "
    "; } } if(isset($_POST["addToCart"])){ $p_id = $_POST["proId"]; if(isset($_SESSION["uid"])){ $user_id = $_SESSION["uid"]; $sql = "SELECT * FROM cart WHERE p_id = '$p_id' AND user_id = '$user_id'"; $run_query = mysqli_query($con,$sql); $count = mysqli_num_rows($run_query); if($count > 0){ echo "
    × Product is already added into the cart continue shopping.
    "; } else { $db_sql = "SELECT * FROM cart"; $db_query = mysqli_query($con, $db_sql); $count_db = mysqli_num_rows($db_query); $sql = "INSERT INTO `cart` (`id`, `p_id`, `ip_add`, `user_id`, `qty`) VALUES ($count_db + 1,'$p_id','$ip_add','$user_id','1')"; if(mysqli_query($con,$sql)){ $sql = "DELETE FROM wishlist WHERE p_id = '$p_id' AND user_id = '$_SESSION[uid]'"; if(mysqli_query($con,$sql)){ echo "
    × Product is added to cart
    "; } } } }else{ $sql = "SELECT * FROM cart WHERE p_id = '$p_id' AND user_id = -1"; $run_query = mysqli_query($con,$sql); $count = mysqli_num_rows($run_query); if ($count > 0) { echo "
    × Product is already added into the cart continue shopping.
    "; exit(); } $db_sql = "SELECT * FROM cart"; $db_query = mysqli_query($con, $db_sql); $count_db = mysqli_num_rows($db_query); $sql = "INSERT INTO `cart` (`id`, `p_id`, `ip_add`, `user_id`, `qty`) VALUES ($count_db + 1,'$p_id','$ip_add','-1','1')"; if (mysqli_query($con,$sql)) { $sql = "DELETE FROM wishlist WHERE p_id = '$p_id' AND ip_add = '$ip_add'"; if(mysqli_query($con,$sql)){ echo "
    × Product is added to cart
    "; exit(); } } } } if(isset($_POST["addToWishlist"])){ $p_id = $_POST["proId"]; if(isset($_SESSION["uid"])){ $user_id = $_SESSION["uid"]; $sql = "SELECT * FROM wishlist WHERE p_id = '$p_id' AND user_id = '$user_id'"; $run_query = mysqli_query($con,$sql); $count = mysqli_num_rows($run_query); if($count > 0){ echo "
    × Product is already added into the wishlist continue shopping.
    "; } else { $db_sql = "SELECT * FROM wishlist"; $db_query = mysqli_query($con, $db_sql); $count_db = mysqli_num_rows($db_query); $sql = "INSERT INTO `wishlist` (`id`, `p_id`, `ip_add`, `user_id`) VALUES ($count_db + 1,'$p_id','$ip_add','$user_id')"; if(mysqli_query($con,$sql)){ $sql = "DELETE FROM cart WHERE p_id = '$p_id' AND user_id = '$_SESSION[uid]'"; if(mysqli_query($con,$sql)){ echo "
    × Product is added to wishlist
    "; } } } }else{ $sql = "SELECT * FROM wishlist WHERE p_id = '$p_id' AND user_id = -1"; $query = mysqli_query($con,$sql); if (mysqli_num_rows($query) > 0) { echo "
    × Product is already added into the wishlist continue shopping.
    "; exit(); } $db_sql = "SELECT * FROM wishlist"; $db_query = mysqli_query($con, $db_sql); $count_db = mysqli_num_rows($db_query); $sql = "INSERT INTO `wishlist` (`id`, `p_id`, `ip_add`, `user_id`) VALUES ($count_db + 1,'$p_id','$ip_add','-1')"; if (mysqli_query($con,$sql)) { $sql = "DELETE FROM cart WHERE p_id = '$p_id' AND ip_add = '$ip_add'"; if(mysqli_query($con,$sql)){ echo "
    × Product is added to wishlist
    "; exit(); } } } } //Count User cart item if (isset($_POST["count_item"])) { //When user is logged in then we will count number of item in cart by using user session id if (isset($_SESSION["uid"])) { $sql = "SELECT COUNT(*) AS count_item FROM cart WHERE user_id = $_SESSION[uid]"; }else{ //When user is not logged in then we will count number of item in cart by using users unique ip address $sql = "SELECT COUNT(*) AS count_item FROM cart WHERE ip_add = '$ip_add' AND user_id < 0"; } $query = mysqli_query($con,$sql); $row = mysqli_fetch_array($query); echo $row["count_item"]; exit(); } //Count User cart item if (isset($_POST["count_Wishlist_item"])) { //When user is logged in then we will count number of item in cart by using user session id if (isset($_SESSION["uid"])) { $sql = "SELECT COUNT(*) AS count_wishlist_item FROM wishlist WHERE user_id = $_SESSION[uid] AND p_id > 0" ; }else{ //When user is not logged in then we will count number of item in cart by using users unique ip address $sql = "SELECT COUNT(*) AS count_wishlist_item FROM wishlist WHERE ip_add = '$ip_add' AND user_id < 0 AND p_id > 0"; } $query = mysqli_query($con,$sql); $row = mysqli_fetch_array($query); echo $row["count_wishlist_item"]; exit(); } //Get Cart Item From Database to Dropdown menu if (isset($_POST["Common"])) { if (isset($_SESSION["uid"])) { //When user is logged in this query will execute $sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_desc,a.product_image,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.user_id='$_SESSION[uid]'"; }else{ //When user is not logged in this query will execute $sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,a.product_desc,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.ip_add='$ip_add' AND b.user_id < 0"; } $query = mysqli_query($con,$sql); if (isset($_POST["getCartItem"])) { //display cart item in dropdown menu if (mysqli_num_rows($query) > 0) { $n=0; $total_price=0; while ($row=mysqli_fetch_array($query)) { $n++; $product_id = $row["product_id"]; $product_title = $row["product_title"]; $product_price = $row["product_price"]; $product_image = $row["product_image"]; $cart_item_id = $row["id"]; $qty = $row["qty"]; $total_price=$total_price+$product_price; echo '

    '.$product_title.'

    '.$n.''.$product_price.'$

    ' ; } echo '
    '.$n.' Item(s) selected
    '.$total_price.'$
    ' ?> 0) { //display user cart item with "Ready to checkout" button if user is not login echo '
    '; $n=0; while ($row=mysqli_fetch_array($query)) { $n++; $product_id = $row["product_id"]; $product_title = $row["product_title"]; $product_price = $row["product_price"]; $product_desc = $row["product_desc"]; $product_image = $row["product_image"]; $cart_item_id = $row["id"]; $qty = $row["qty"]; echo ' '; } echo '
    Product Price Quantity Subtotal

    '.$product_desc.'

    Move to Wishlist
    Continue Shopping '; if (!isset($_SESSION["uid"])) { echo ' Ready to Checkout
    '; }else if(isset($_SESSION["uid"])){ //Paypal checkout form echo '
    '; $x=0; $sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.user_id='$_SESSION[uid]'"; $query = mysqli_query($con,$sql); while($row=mysqli_fetch_array($query)){ $x++; echo ' '; } echo '
    '; } } } } if (isset($_POST["wishListCommon"])) { if (isset($_SESSION["uid"])) { //When user is logged in this query will execute $sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,a.product_desc,b.id FROM products a,wishlist b WHERE a.product_id=b.p_id AND b.user_id='$_SESSION[uid]'"; }else{ //When user is not logged in this query will execute $sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,a.product_desc,b.id FROM products a,wishlist b WHERE a.product_id=b.p_id AND b.ip_add='$ip_add' AND b.user_id < 0"; } $query = mysqli_query($con,$sql); if (isset($_POST["wishlistDetails"])) { if (mysqli_num_rows($query) > 0) { //display user cart item with "Ready to checkout" button if user is not login echo '
    '; $n=0; while ($row=mysqli_fetch_array($query)) { $n++; $product_id = $row["product_id"]; $product_title = $row["product_title"]; $product_desc = $row["product_desc"]; $product_price = $row["product_price"]; $product_image = $row["product_image"]; $wishlist_item_id = $row["id"]; echo ' '; } echo '
    Product Price Subtotal

    '.$product_desc.'

    Move to Cart
    Continue Shopping
    '; } } } //Remove Item From cart if (isset($_POST["removeItemFromCart"])) { $remove_id = $_POST["rid"]; if (isset($_SESSION["uid"])) { $sql = "DELETE FROM cart WHERE p_id = '$remove_id' AND user_id = '$_SESSION[uid]'"; }else{ $sql = "DELETE FROM cart WHERE p_id = '$remove_id' AND ip_add = '$ip_add'"; } if(mysqli_query($con,$sql)){ echo "
    × Product is removed from cart
    "; exit(); } } if (isset($_POST["removeItemFromwishList"])) { $remove_id = $_POST["rid"]; if (isset($_SESSION["uid"])) { $sql = "DELETE FROM wishlist WHERE p_id = '$remove_id' AND user_id = '$_SESSION[uid]'"; }else{ $sql = "DELETE FROM wishlist WHERE p_id = '$remove_id' AND ip_add = '$ip_add'"; } if(mysqli_query($con,$sql)){ echo "
    × Product is removed from wishlist
    "; exit(); } } //Update Item From cart if (isset($_POST["updateCartItem"])) { $update_id = $_POST["update_id"]; $qty = $_POST["qty"]; if (isset($_SESSION["uid"])) { $sql = "UPDATE cart SET qty='$qty' WHERE p_id = '$update_id' AND user_id = '$_SESSION[uid]'"; }else{ $sql = "UPDATE cart SET qty='$qty' WHERE p_id = '$update_id' AND ip_add = '$ip_add'"; } if(mysqli_query($con,$sql)){ echo "
    × Product is updated
    "; exit(); } } ?>