I am making a registration form and in one part I request the nationality of the person, which is selected from a table in SQL
<p style="text-align:center;"><label><select id="lista" name="Nacionalidad">
<?php
include 'conexion.php';
$consulta = "SELECT CveNacion,Nacionalidad FROM catnacion";
$resultado = $mysqli->query($consulta);
?>
<form action="" method="post" class="form-login">
<?php foreach ($resultado as $opciones) : ?>
<option value="<?php echo $opciones['Nacionalidad'] ?>">
<?php echo $opciones['CveNacion'].' '.substr($opciones['Nacionalidad'],0,15) ?>
</option>
<?php endforeach ?>
</select></label></p>
The problem is that when performing the $consulta = "SELECT CveNacion,Nacionalidad FROM catnacion";
it is displayed as follows:
I would like the first value displayed to be Mexico:
As follows:
I have tried to carry out an ORDER BY starting from the M like this SELECT CveNacion,Nacionalidad FROM catnacion ORDER BY Nacionalidad>"M"
, but it does not do it as I want, is there any way that from the query it shows me that result first or I can do it directly in the form, thank you very much in advance
If it doesn't matter how the rest of the data is displayed, what I would do to display the value of Mexico by default would be to add a condition:
Being that way:
Then then it will always show you by default Mexico
You could put a
CASE
in the expressionORDER BY
so that it puts Mexico first and the values that you require.