Senthilkumar Posted December 17, 2022 Share Posted December 17, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315656-filter-table-data-using-multiple-drop-box/ Share on other sites More sharing options...
requinix Posted December 18, 2022 Share Posted December 18, 2022 You've given every field its own distinct <form>. If you want to access all the fields at once then you have to put them all in the same form. Quote Link to comment https://forums.phpfreaks.com/topic/315656-filter-table-data-using-multiple-drop-box/#findComment-1603680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.