Hello,

I was wondering if any one help me ouut guide me or let me know how do i filter records using php like it is done in property listings product listings etc I am stuck up can anypne help me out with that.

Thank You

<form action="" method="POST">
        <div class="option">
            <select>
            <?php 
                $get_prod = find_all_products();
                echo "<option>Brand</option>";
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["brand"] . "</option>";
                }
            ?>
            </select>
        </div>

        <div class="option">
            <select>
                <option>Model</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["model"] . "</option>";
                }
            ?>
            </select>
        </div>

        <div class="option">
            <select>
                <option>Refrence</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["reff"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Material</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["mtrl"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Condition</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["cond"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Seller</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["seller"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Box</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["box"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Discount %</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["disc"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Papers</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["paper"] . "</option>";
                }
            ?>  
            </select>
        </div>

        <div class="option">
            <select>
                <option>Price $</option>
            <?php 
                $get_prod = find_all_products();    
                while($prod_row = mysqli_fetch_assoc($get_prod)) {
                    echo "<option>" . $prod_row["price"] . "</option>";
                }
            ?>  
            </select>
        </div>

From the looks of it.. your function find_all_products() makes a database call, then you churn through the results as needed.

This is just terribly inefficient. You do not seem to be changing the SQL in any way for each call, so just do it once and store the values locally in either an object, or an associative array (if that makes you happy). Or, an array of Objects (which seems to be the best solution in your case).

Then, instead of doing the database calls over and over again, you simply iterate through your local array of objects and pull whatever data you need at the time.

Hope that helps!

Member Avatar for diafol

Agree with RT. This makes no sense at all. Looks to me that you have one big table - which is wrong. Your data should be in related tables.

Be a part of the DaniWeb community

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