I have this code
<?php
$country=$result['pais'];
}
$strSQL = "SELECT id, nombre FROM paises";
$query = mysqli_query($db, $strSQL);
$totalrows = mysqli_num_rows($query);
?>
<select class="form-control" name="acccountry">
<?php
while($result = mysqli_fetch_array($query)){
?>
<option <?php ($r == $country) ? 'selected' : '' ;?> value="<?php echo $result['id']; ?>"><?php echo $result['nombre'];?></option>
<?php } ?>
</select>
Before that I have a query from another table in which I get the code of a country, that's why I have the variable $country
. What I want is that I go through the table and where the IDs match I put that option as selected
in <option>