Populate table based on selected dropdown value

Please Help! I want to know where to put the condition to display data in a table after I select the value from a dropdown list. Both have the same id (dropdown and table).

I need to use ajax and jquery but I didn’t know how to create that piece of code for my problem. when I select an item from dropdown I want to see in table the employees with the job id as one from dropdown.

Also , i need to keep the second query, because this is just an example but in my code i have a diferent query(2) who take data from 3 tables and has the same id as the dropdown.

Sorry for my english!

                              <?php $con=mysqli_connect("localhost","root","root","company");
                              // Check connection
                              if (mysqli_connect_errno())
                               echo "Failed to connect to MySQL: " . mysqli_connect_error();
                                $sql="SELECT employees.id,employees.jobs FROM employees WHERE employees.jobs in ("programmer","hr","qa")";
                                 if ($result=mysqli_query($con,$sql))
                              <label for="y">Select the job:</label>
                              <select name="loads" id="loads" onchange=""> 
                              <?php while($ri = mysqli_fetch_array($result)) {
                              <option value="<?php echo $ri['id'];?>" >  <?php echo $ri['jobs']; ?> </option>
                             <table class="striped" border="1" align="center" id="demo">
                                   <tr class="header">
                                        <td align="center"><b>Name</b></td>
                                    $sql2="SELECT employees.id,employees.name FROM employees WHERE employees.jobs in ("programmer","hr","qa")";

                                if ($result=mysqli_query($con,$sql2)){
                               // Fetch one and one row
                                while ($row=mysqli_fetch_array($result))

                                    echo "<tr>";
                                    echo "<td>" . $row["name"] . " " . "</td>";

                               echo "</tr>";



In the SQL statement. althought I’m surprised that this code works at all.

it is just an example. my code does something else but I want to know what is the correct method to extract data in table when i select a value from dropdown. I must use ajax and jquery .

i don’t see any relation between your dropdown and the table - both statements gather the same records, except for the different columns. and also as @Dormilich mentioned, i see a rare chance that your code will not raise at least a syntax error for $sql

I say again. it’s just an example!! I confirm my code works fine but is too complex and I can’t post it here. I wanted to show that the relation between dropdown and table is “employees.id”. having this column in my table and select tag contain it too (as value of option tag) how can i make a link between them and make table populate with particular informations? Just ignore the example. I want to know the ideea, the method to resolve this issue.

if you have the same records in both results i do not see what your problem (or even the idea behind) this question is.

Nevermind. I’ll fix it ! Thanks for your time!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.