Return of "?" instead of special characters in a SELECT [duplicate]

2

I have a problem, I have already coded everything with utf-8, I tried in many ways to sort this out and I can not, in a% of HTML, I pull a table from the database, but it returns with a symbol of special characters instead of the accents as in the picture below:

Thecodefor<option>isthis

<selectid="modalidade" name="modalidade" class="form-control">
        <?php
            header("Content-type:text/html; charset=utf-8");
            //require_once ('../model/Conexao.php');
            //mysql_set_charset('utf8');
            $sql = "SELECT * FROM modalidade";
            $cnx = mysqli_connect("localhost", "root", "", "olimpiada");
            $resultado = mysqli_query($cnx,$sql,MYSQLI_STORE_RESULT);
            $qtde = mysqli_num_rows($resultado);

            if($qtde>0)
            {
                while($linha = mysqli_fetch_array($resultado))
                {

                    echo "<option value=".$linha['idModalidade'].">";
                    echo $linha['modalidade'];
                    echo "</option>";

                }
            }
        ?>
</select>

Here is the structure of the database

Thank you in advance

    
asked by anonymous 30.06.2017 / 20:55

1 answer

2

Use the PHP function utf8_encode() , utf8_encode($linha['modalidade']);

Or change your table in the database to SET=utf8 COLLATE utf8_unicode_ci

    
30.06.2017 / 21:03