hi guys i want to fiter data based on user input. user have to select the company in first input and then game in second tab, so i am trying to show them only games from selected company (which user select in first tab). here is my code if anyone can help me plzzz
<div class="form-group">
<label for="company">Company Name</label>
<select name="company" autocomplete="off">
<?php $sql = "SELECT * from clients having manager like '%$uname%'" ;
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<option value="<?php echo htmlentities($result->company);?>"><?php echo htmlentities($result->company);?></option>
<?php
}} ?>
</select>
</div>
<div class="form-group">
<label for="game">Game Name</label>
<select name="game" autocomplete="off">
<?php $sql = "SELECT * from clientgames having company like '%..........????......%'" ;
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<option value="<?php echo htmlentities($result->gamename);?>"><?php echo htmlentities($result->gamename);?></option>
<?php }} ?>
</select>
</div>
My Answer:
Sure, here is an example code snippet in JavaScript that demonstrates how to filter input fields based on previous input:
html
In this code snippet, we have two select elements - one for selecting the company and another for selecting the game. The games are associated with a specific company using the `data-company` attribute.
When the user selects a company, the `filterGames` function is called, which filters the games based on the selected company. It loops through all the game options and checks if the `data-company` attribute matches the selected company. If it matches, the game option is displayed, otherwise, it is hidden.
You can customize this code further based on your requirements and styling preferences. Let me know if you need any more help!
Rate this post
5 of 5 based on 3601 votesComments