Jump to content

filter table data using multiple drop box


Senthilkumar

Recommended Posts

Hi team,

I amusing 3 drop box on my page inside 3 different forms. Users, Department and Assigned.

The user form is used to select the user and sending to another table.

The Department and Assigned form is using to filter the table data's.

In this i am facing the problem is, when ever is am selecting any of the drop box it resetting another drop box values.

if i select any of one of the drop box, it should not reset another drop box which is already selected.

<form method="get" >
                <select name="tb1" onchange="submit()">
                    <option>Select User</option>
                        <?php
                        $qry    =   mysqli_query($conn,"SELECT DISTINCT Name FROM users ORDER BY Name ASC");
                        while($row = $qry->fetch_assoc()) {
                            echo "<option";
                            if(isset($_REQUEST['tb1']) and $_REQUEST['tb1']==$row['Name']) echo ' selected="selected"';
                            echo ">{$row['Name']}</option>\n";
                        }
                        ?>
                </select>
            </form>
<th scope="col" style="width:20%">   
                                    <form  method="get" >
                                        <select class="background" name="Department" onchange="submit()">
                                            <option>Department</option>
                                                <?php
                                                $qry    =   mysqli_query($conn,"SELECT DISTINCT Department FROM points ORDER BY Department ASC");
                                                while($row = $qry->fetch_assoc()) {
                                                    echo "<option";
                                                    if(isset($_REQUEST['Department']) and $_REQUEST['Department']==$row['Department']) echo ' selected="selected"';
                                                    echo ">{$row['Department']}</option>\n";
                                                }
                                                ?>
                                        </select>
                                    </form>
                                </th>
                                <th scope="col" style="width:20%">
                                    <form  method="get" >
                                        <select class="background" name="Assigned" onchange="submit()">
                                            <option>Assigned to</option>
                                                <?php
                                                $qry    =   mysqli_query($conn,"SELECT DISTINCT Assigned FROM points ORDER BY Assigned ASC");
                                                while($row = $qry->fetch_assoc()) {
                                                    echo "<option";
                                                    if(isset($_REQUEST['Assigned']) and $_REQUEST['Assigned']==$row['Assigned']) echo ' selected="selected"';
                                                    echo ">{$row['Assigned']}</option>\n";
                                                }
                                                ?>
                                        </select>
                                    </form>
                                </th>
<?php

                            $condition      =   "";

                              
                            if(isset($_GET['Department']) and empty(isset($_GET['Assigned'])))
                                {
                                    $condition      .=  " AND Department ='".$_GET['Department']."'";
                                }
                           

                            if(isset($_GET['Assigned']) and empty(isset($_GET['Department'])))
                                {
                                    $condition      .=  " AND Assigned ='".$_GET['Assigned']."'";
                                }

                            if(!empty(isset($_GET['Department'])) and !empty(isset($_GET['Assigned'])))
                            //if(isset($_GET['Department']) and  isset($_GET['Assigned']))
                            {
                                $condition      .=  " AND Department ='".$_GET['Department']."' AND Assigned ='".$_GET['Assigned']."'";
                            }

                           
                            

                            $qryStr     =   "SELECT * FROM points WHERE 1 ".$condition." ORDER BY Point_id ASC";
                              $qry    =   mysqli_query($conn, $qryStr);

I am attaching my file here for your reference. Please help me to solve this.

Assignment.txt

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.