developed an admin panel in which users can add products from there and I put fields over there as size and color for the dresses dresses sizes and color would be more then 1 so I made 2 more tables in the database named prod_size and prod_color here is the table structure

table name : prod_size

| prod_id | size |
|   6     |   S  |
|   6     |   M  |
|   6     |   L  |
|   7     |   S  |
|   7     |   M  |

table name : prod_color

| prod_id | color |
|   6     | white |
|   6     | blue  |
|   6     | black |
|   7     | orange|
|   7     | black |

and third one is products table where the products are stored tabl name : products

  `prod_id` int(11) NOT NULL AUTO_INCREMENT,
  `product_name` varchar(255) NOT NULL,
  `product_price` int(11) NOT NULL,
  `product_image` varchar(255) NOT NULL,
  `product_category` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `status` varchar(255) NOT NULL,
  `template` varchar(255) NOT NULL,
  PRIMARY KEY (`prod_id`)

Now on the front end here comes the problem for me when I start developing filter search result when I search it with range works fine but now how do I make it filter by color and size here is the code which I had used fr filtering by price??? Here in this field the input fields i.e check boxes will be dynamic right now I am assuming

<form method="POST" action="product.php">
            <div class="price-box">
                <input type="hidden" name='price_range' class="range-slider" min="0" max="600" value="23" />
            <div class="size-box">
                    <li> <input type="checkbox" name="option[]" value=""> <span class="check-txt">S (10)</span></li>
                    <li> <input type="checkbox" name="option[]" value=""> <span class="check-txt">M (10)</span></li>
                    <li> <input type="checkbox" name="option[]" value=""> <span class="check-txt">L (10)</span></li>

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

For refine search result I used the following code


                        if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
                        $start_from = ($page-1) * $num_rec_per_page;

                        if(isset($_POST['filter'])) {
                            $range = $_POST['price_range'];
                            $rg = explode(',', $range);
                            $range1 = $rg[0];
                            $range2 = $rg[1];
                            $get_prod = mysqli_query($connection, "SELECT * FROM products WHERE product_price BETWEEN '$range1' AND '$range2' LIMIT $start_from, $num_rec_per_page");
                        } else {
                            $get_prod = query('products', "LIMIT $start_from, $num_rec_per_page");
                        $total = mysqli_num_rows($get_prod);
                        while($prod = mysqli_fetch_assoc($get_prod)) {
1 Year
Discussion Span
Last Post by amigura

you need values in your size and colour forms.

<form action="" method="post">
<input type="checkbox" name="colour[]" value="red"><label>red</label><br/>
<input type="checkbox" name="colour[]" value="blue"><label>blue</label><br/>
<input type="checkbox" name="colour[]" value="black"><label>black</label><br/>
<input type="submit" name="submit" value="Submit"/>

foreach($_POST['colour'] as $v){
echo $v."</br>";

Edited by amigura

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.