List / Static menu showing bank option

0

I wish I could understand a problem I have here. I created a static list / menu, but I need to leave marked option recorded in the database, when I have a table that allows me the relationship I make legal, as in this case:

<?php  
    mysql_select_db($database_conCurriculo, $conCurriculo);
    $QueryEstado = "SELECT * FROM estado_civil";
    $EstadoCivil = mysql_query($QueryEstado, $conCurriculo) or die(mysql_error());
    while ($row_EstadoCivil = mysql_fetch_assoc($EstadoCivil)) {
        echo "<option value='".$row_EstadoCivil["id"]."'"; 
        if ($estadocivil == $row_EstadoCivil["id"]) { 
            echo "selected";
        }
        echo ">".$row_EstadoCivil["estado"]."</option>\n";
    }
?>

In the above case I have the table * civil_status * I check if the $estadocivil is equal to what is in the database and leave the option selected, but my problem is that I do not have a table that allows me this interaction. I created a List / Menu with the static options and would like to know how to mark the option that is in the bank.

What I have is this:

<select name="nivelingles" id="nivelingles">
    <option value="0" selected="selected">Selecione</option>
    <option value="B&aacute;sico">B&aacute;sico</option>
    <option value="Intermedi&aacute;rio">Intermedi&aacute;rio</option>
    <option value="Avan&ccedil;ado">Avan&ccedil;ado</option>
</select>

In the database I have written in the nivel_ingles field the "Intermediate" option, could anyone help me or give me some tips on how to do it?

Thanks and stay in peace.

    
asked by anonymous 11.03.2014 / 17:56

1 answer

2

I believe something like this should work:

<select name="nivelingles" id="nivelingles">
    <option value="0" selected="selected">Selecione</option>
    <option value="B&aacute;sico" 
        <?php if ($nivel_ingles == "Básico") {echo "selected";} ?> 
    >B&aacute;sico</option>

    <option value="Intermedi&aacute;rio"
        <?php if ($nivel_ingles == "Intermediário") {echo "selected";} ?>
    >Intermedi&aacute;rio</option>

    <option value="Avan&ccedil;ado"
        <?php if ($nivel_ingles == "Avançado") {echo "selected";} ?>
    >Avan&ccedil;ado</option>
</select>
    
11.03.2014 / 19:47