hi I’m beginner in php coding i have a problem to display the previously selected value in drop down list when im editing its blank regardless of its selected value as I have two tables table admin_profile which i keep record of users and table of current_jobs I’m fetching the username of the users to be displayed in a drop down list to be stored in table column checker
here is my code
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<?php
$query ="SELECT user_name FROM admin_profile
where user_role='Checker' or user_role='Designer' ";
$result = $conn->query($query);
if($result->num_rows> 0){
$options = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
?>
<label>Checker</label>
<select class="form-control" name="checker" id="checker" >
<option value="" ></option>
<?php
foreach ($options as $option) {
?>
<option value=""><?php echo $option ['user_name']; ?> </option>
<?php
}
?>
</select>
I tried this code but its not working
<option <?php if (!empty($checker) && $checker == $option['user_name']) echo "selected"; ?>> </option>
2
Answers
i was able to solve it thanks
It appears blank because in your code, the value attribute is not assigned anything (value=""). What you need to do is assign the correct value to each option. Essentially, the code you attempted to test should be placed within the value attribute:
Let me know if it works