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 "
";
}
}
}
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 "
";
}
}
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..!
";//not in video
} 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 removed from wishlist and 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 removed from wishlist and 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..!
";//not in video
} 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 removed from cart and 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 removed from cart and 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 '
'
;
}
echo '
'.$n.' Item(s) selected
Rs'.$total_price.'
'
?>
0) {
//display user cart item with "Ready to checkout" button if user is not login
echo '
';
}else if(isset($_SESSION["uid"])){
//Paypal checkout form
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 '