I have built a dropdown list using PHP to show all the Unique names in my Table. I want to use that dropdown list to then use the selected value to create a MySQL Statement Dynamically.
Select * From iot_sensors WHERE Sensor_ID = ['USE the DROPDOWN MENU TO SELECT A NAME']
$select2 = "SELECT DISTINCT Sensor_ID FROM iot_sensors;";
$result2 = mysqli_query($conn, $select2);
$counter2 = mysqli_num_rows($result2);
echo "<select name ='Sensor Names'>";
while ($row = mysqli_fetch_assoc($result2)){
echo "<option value ='".$row['Sensor_ID']."'>".$row['Sensor_ID']." </option>";
}
$dynamic_query = "SELECT * FROM iot_sensors WHERE Sensor_ID = ['option value']";
echo "</select>";
I understand usually if I had manually populated the dropdown menu all I would have to do is call the option value but here the option value is on there for HTML rendering purposes.