I have created a filter result using php but it is not properly working for me when i filter result it is not showing me up with any products

<form method="POST" action="product.php?cat=<?php echo $cat; ?>">
        <div class="price-box">
            <input type="hidden" name='price_range' class="range-slider" min="0" max="600" value="23" />
        <div id="filters">
        <div class="size-box">
                <li> <input type="checkbox" id="active" name="size[]" value="S"> <span class="check-txt">S (10)</span></li>
                <li> <input type="checkbox" id="In Stock" name="size[]" value="XL"> <span class="check-txt">XL (10)</span></li>
                <li> <input type="checkbox" id="large" name="size[]" value="L"> <span class="check-txt">L (10)</span></li>

        <div class="color-box">
                <li> <input type="checkbox" name="color[]" value="White"> <span class="check-txt">White (2)</span></li>
                <li> <input type="checkbox" name="color[]" value="Black"> <span class="check-txt">Black (3)</span></li>
                <li> <input type="checkbox" name="color[]" value="Orange"> <span class="check-txt">Orange (3)</span></li>
                <li> <input type="checkbox" name="color[]" value="Blue"> <span class="check-txt">Blue (4)</span></li>
                <li> <input type="checkbox" name="color[]" value="Green"> <span class="check-txt">Green (2)</span></li>
                <li> <input type="checkbox" name="color[]" value="Yellow"> <span class="check-txt">Yellow (1)</span></li>

        <div class="styles-box">
                <li> <input type="checkbox" name="option1" value="Casual"> <span class="check-txt">Casual (3)</span></li>
                <li> <input type="checkbox" name="option1" value="Dressy"> <span class="check-txt">Dressy (2)</span></li>
                <li> <input type="checkbox" name="option1" value="Girly"> <span class="check-txt">Girly (4)</span></li>

        <input type="submit" name="filter" value="Filter Results" />

And here is my php code

                if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
                        $start_from = ($page-1) * $num_rec_per_page;                    
                        $query = "SELECT * FROM products WHERE product_category = '$cat'";
                                $query = "SELECT p.* FROM products as p
                                  JOIN prod_size as ps ON (p.prod_id=ps.prod_id)
                                  JOIN prod_color as pc ON (p.prod_id=pc.prod_id)
                                  WHERE ";
                                $range = $_POST['price_range'];
                                $rg = explode(',', $range);
                                $range1 = $rg[0];
                                $range2 = $rg[1];
                                if($range1!='' && $range2!='')
                                {   $query .= " p.product_price BETWEEN (".$range1." AND ".$range2.") AND ";    }

                                if(isset($_POST['size']) && is_array($_POST['size']))
                                {   $size = implode(',',$_POST['size']);
                                    $query .= " ps.size IN ('".$size."') AND ";     }

                                if(isset($_POST['color']) && is_array($_POST['color']))
                                {   $color = implode(',',$_POST['color']);
                                    $query .= " pc.color  IN ('".$color."') AND ";      }
                                    $query .= " p.prod_id > 0 ";

                                $query .= " LIMIT ".$start_from.",".$num_rec_per_page;
                                $get_prod = mysqli_query($connection, $query);

                        $total = mysqli_num_rows($get_prod);
                        while($prod = mysqli_fetch_assoc($get_prod)) {
                    <li class='resultblock' data-tag='<?php echo $prod['status']; ?>'>
                        <span class="cbp-vm-image">
                            <img src="admin/uplaods/<?php echo $prod['product_image']; ?>" alt="">
                                <li><a href=""><i class="fa fa-heart"></i></a></li>
                                <li><a href=""><i class="fa fa-refresh"></i></a></li>
                                <li><a href=""><i class="fa fa-search"></i></a></li>

                        <p class="cbp-vm-title"><?php echo $prod['product_name']; ?></p>

                        <ul class="cbp-vm-price">
                            <li>$<?php echo $prod['product_price']; ?></li>
                            <li class="pro-rating"><span><i class="fa fa-star"></i></span> <span><i class="fa fa-star"></i></span> <span><i class="fa fa-star"></i></span> <span><i class="fa fa-star"></i></span> <span><i class="fa fa-star"></i></span></li>
                        <a class="cbp-vm-icon cbp-vm-add" href="details.php?pid=<?php echo $prod['prod_id'];?>">View Details</a>
                    <?php } ?>

Recommended Answers

All 2 Replies

“ it is not properly working for me “ don't describe the problem , moreover if you really want help don't paste your view paste only you PHP logic code

Member Avatar

What have you investigated? Echo out key variables at specific places to see what they're doing. Otherwise use a debugger, e.g. xdebug and watch variable values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.