if online php does not work

3

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>

    
asked by Pavlo B. 28.10.2016 в 10:45
source

2 answers

3

You're missing echo :

<?php echo ($r == $country) ? 'selected' : '' ;?>
    
answered by 28.10.2016 / 10:48
source
0

Use:

<?php echo ($r == $country) ? 'selected' : '' ;?>

Or the abbreviated version:

<?= ($r == $country) ? 'selected' : '' ?>
    
answered by 28.10.2016 в 10:51