I'm developing a simple application that allows to insert, modify and delete employees.
The problem I have is with the Person Edit Page. Here I have some text inputs and some dropdowns.
When I edit the person details I'm loading data from the DB and display them in the respective fields.
The problem is with the dropdowns, the query that contains the person details, contains data just for that person where as for the City perhaps, I would need to load all the cities from the DB, here an example:
<?php
if ($result2->num_rows > 0) {
// output data of each row
while($row = $result2->fetch_assoc()) {
echo "<div class='form-group'>
<label>Name</label>
<input class='form-control' value='". $row["Name"] . "'>
</div>
<div class='form-group'>
<label>email</label>
<input class='form-control' value='". $row["email"] . "'>
</div>
<div class='form-group'>
<label>City</label>
<select class='form-control'>
<option selected>". $row["City"] . "</option>
<option>New York</option>
<option>Boston</option>
<option>San Francisco</option>
</select>
</div>";
}
}
?>
In the "while", I loop $result2 which contains a query like this:
Select name, email, city from emp where id = 100;
When I edit the person details from the app, the city dropdown will load the right city but I would need to load all the cities (that I don't have in $result2) in order to be able to modify it.
Would be like a nested loop but I'm not sure how to implement it.
Any help appreciated
Thank you