0

Hello.

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">
            <h5>Price</h5>
            <input type="hidden" name='price_range' class="range-slider" min="0" max="600" value="23" />
        </div>
        <div id="filters">
        <div class="size-box">
            <h5>size</h5>
            <ul>
                <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>
            </ul>
        </div>
        </div>

        <div class="color-box">
            <h5>color</h5>
            <ul>
                <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>
            </ul>
        </div>

        <div class="styles-box">
            <h5>Styles</h5>
            <ul>
                <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>

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

And here is my php code

            <?php
                $num_rec_per_page=9;
                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'";
                            if(isset($_POST['filter']))
                            {
                                $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="">
                            <ul>
                                <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>
                            </ul>
                        </span>

                        <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>
                        </ul>
                        <a class="cbp-vm-icon cbp-vm-add" href="details.php?pid=<?php echo $prod['prod_id'];?>">View Details</a>
                    </li>
                    <?php } ?>
                    </ul>
3
Contributors
2
Replies
10
Views
1 Year
Discussion Span
Last Post by diafol
0

“ 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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.