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!
<html>
<head>
</head>
<body>
<?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>
<?php
}
}
?>
</select>
<table class="striped" border="1" align="center" id="demo">
<tr class="header">
<td align="center"><b>Name</b></td>
</tr>
<?php
$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>";
}
}
mysqli_close($con);
?>
</table>
</body>
</html>