List/Static menu showing database option

Asked

Viewed 453 times

0

I wish I could understand a problem I have here. I created a static list/ menu, but I need to leave marked option saved in the bank, when I have a table that allows me the relationship I do cool, 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 *state_civil* there I check if the $estadocivil is the same as the one in the bank and I leave the option selected, but in my problem is that I don’t have a table that allows me this interaction. I created a List/Menu with static options and would like to know how to mark the option that is in the database.

What I got 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>

On the bench I have recorded in the field nivel_ingles the option "Intermediary", would someone help me or give me some hint on how to do?

Thank you and be at peace.

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>
  • 1

    Hello "rocmartins". Thank you very much for the help, I was having problems accentuating, I appreciate the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.