create a select within the while

1

I have this query:

while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {

$tabela1 .= '<tr>';

$tabela1 .= '<td style="font-size: 12px">'.$rows_cursos['DataAprovacao'].'</td>';

$tabela1 .= '<td style="font-size: 12px">'.$rows_cursos['IdTipoProduto'].'</td>';

$tabela1 .= '<td style="font-size: 12px">'.$rows_cursos['IdProduto'].'</td>';

$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['Quantidade'].'</td>';

$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['IdRequerente'].'</td>';

$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['IdDestino'].'</td>';

$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['Estado'].'</td>';

$tabela1 .= '<td> <select data-qtd3="Fornecedor" style="width:106px" name="Fornecedor[]" id="Fornecedor">
<option></option>
<?php        
         $sql = "SELECT * FROM Fornecedor ORDER BY Fornecedor ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['Id'].'">'.$ln['Fornecedor'].'</option>';
         }
      ?>        
</select></td>';

$tabela1 .= '</tr>';

}

Only select

$tabela1 .= '<td> <select data-qtd3="Fornecedor" style="width:106px" name="Fornecedor[]" id="Fornecedor">
    <option></option>
    <?php        
             $sql = "SELECT * FROM Fornecedor ORDER BY Fornecedor ASC";
             $qr = mysqli_query($conn, $sql);
             while($ln = mysqli_fetch_assoc($qr)){
                echo '<option value="'.$ln['Id'].'">'.$ln['Fornecedor'].'</option>';
             }
          ?>        
    </select></td>';

is not working. Does not return the vendor data I have in the database table

    
asked by anonymous 25.07.2018 / 12:57

1 answer

2

Try this:

$tabela1 .= '<td> <select data-qtd3="Fornecedor" style="width:106px" name="Fornecedor[]" id="Fornecedor">';

$sql = "SELECT * FROM Fornecedor ORDER BY Fornecedor ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
    $tabela1 .= '<option value="'.$ln['Id'].'">'.$ln['Fornecedor'].'</option>';
}

$tabela1 .= '</select></td>';

The way I was doing you were adding PHP to queries within the string associated with $tabela1 .

I imagine you were trying to get this snippet of PHP to run when the $tabela1 variable was printed. Instead, look for options popular while setting up the table.

    
25.07.2018 / 13:42