How to make a select`Multiple` start with the first option already marked PHP Mysql

Asked

Viewed 79 times

0

Follows my component:

       $query_menu = mysql_query("SELECT 
       rm_id     AS FUNCAO,
       rm_desc   AS DESCRICAO,
       rm_obs    AS OBSERVACAO,
       rm_status AS STATUS 
            FROM radios_menu 
                 WHERE rm_status='0'");

echo"<div class='form-group'>";
  echo"<div class='col-lg-12'>";
    echo"<select multiple='' id='v_desc' name='v_desc' class='form-control'>";
while ($row = mysql_fetch_array($query_menu)){
         $v_funcao    = $row["FUNCAO"];
         $v_desc      = $row["DESCRICAO"];
         $v_obs       = $row["OBSERVACAO"];
         $v_status    = $row["STATUS"];
    echo"<option value='$v_funcao'>$v_desc</option>"; 
         }
    echo"</select>";
  echo"</div>";
echo"</div>";  

With the help of @caiocafardo worked, but in the stylization there was only one thing I would like to change: My chosen item is blue: inserir a descrição da imagem aqui But @caiocafardo turns gray: inserir a descrição da imagem aqui

How could I make them both turn blue ? I’m wearing the bootstrap.

1 answer

1


Just make sure it’s the first pass through WHILE:

$checaPrimeiro = 1;
$checaSeleciona = "";
while ($row = mysql_fetch_array($query_menu)){
    $v_funcao    = $row["FUNCAO"];
    $v_desc      = $row["DESCRICAO"];
    $v_obs       = $row["OBSERVACAO"];
    $v_status    = $row["STATUS"];
    //
    if($checaPrimeiro == 1){
        $checaSeleciona = "selected";
    }else{
        $checaSeleciona = "";
    }
    echo "<option value='$v_funcao' $checaSeleciona>$v_desc</option>"; 
    $checaPrimeiro++;
}
  • Perfect, it worked,more see if you can help me in styling,complemented the question.

  • @Otaciobarbosa this should help you: http://stackoverflow.com/questions/24346956/how-to-change-bootstrap-3-selected-option-background-color

Browser other questions tagged

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