<select class="form-control" name="cliente">
....
</select>
These lines are the opening and closing of the HTML tag to create a selection object (combo box or select) on the HTML page, not to perform a select on a database. Probably this select has already been performed at an earlier point in the code, not shown in your example.
<?php if ($clientes) {
foreach($clientes as $ind => $valor) {
?>
<option value="<?php echo $valor->nome ?>"><?php echo $valor->nome ?></option>
<?php } } ?>
In this code portion the combo box object is populated with the options. In the line with the if
is tested if the $clients variable has a true value, in this case if it is the "result" of the bank search, if it is null it will be considered false and does not enter if, otherwise probably why it has return values, enter.
In the block of foreach
each record of the query result is covered and the index placed in $ind
and the registration in $valor
. The line starting with the tag mounts the choice option that will be shown in the combo box object.
What the above code does is to check if there is any value in the $clients variable and if there is it prints the clients name in a select. Creating a select of customer names!
– alan
This code is creating the options of a dropdow(Select) but without knowing the whole scope of the application it is difficult to know what the purpose of using it is. By the way you should know where this comes from...
– Felipe Assunção
this if validation ($clients) is not very good. leaves gap for errors. For example: $clients = [array()]; it would pass its validation and generate the following error in its foreach: "NOTICE Trying to get Property of non-object on line number 7"
– alan