2
I would like some help on the following question. When I selected an item in a combobox (it would be for a search filter), I wanted this item to remain selected after pressing the "Query" button. Below, follows a part of the code. If you are missing some information, sorry. Just say so , I provide more information.
<div class="col-md-3">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Sistema</label>
<div class="col-md-6">
<select class="form-control" name="sistema">
<option value="" >Todos</option>
<?php
$sql = mysql_query("SELECT * FROM sistema WHERE Codigo = 12 ORDER BY Descricao");
while ($sistema = mysql_fetch_array($sql)) {
echo '<option value=' . $sistema['Codigo'] . ' selected>' . $sistema ['Descricao'] . '</option>';
}
$sql = mysql_query("SELECT * FROM sistema WHERE Codigo <> 12 ORDER BY Descricao");
while ($sistema = mysql_fetch_array($sql)) {
echo '<option value=' . $sistema['Codigo'] . '>' . $sistema['Descricao'] . '</option>';
}
?>
</select>
</div>
</div>
</div>
Because it has 2 querys related to id 12 ? a = and a different ? would be a test
– Bulfaitelo
Does the "Query" button submit the form? And how is this request, GET or POST? To which URL?
– Woss
One query serves to leave a system selected by default. The other, shows the list of systems that are in the database.
– Samuel Ribeiro Braz
is POST request.
– Samuel Ribeiro Braz
To leave a default you could put the pure html out of the loop, or check inside the loop if the current system is what you want and leave selected.
($sistema['Codigo'] == 12? 'selected':'')
– edson alves