-1

I would like to add a select with information from the database and save it in a variable. Unfortunately it doesn't work for me, it just shows me one record and not all records.

$sql = $conn->query("SELECT * FROM recaudacionBancaria")
foreach ($sql as $key => $value) {
    // class='theClass' value='".$value['cuenta']."'idCuenta='".$value['id']."'></div>";
    $cuenta = "<div class='btn-group'><select  class='form-control input-xs cue' name='cue' id='cue'>
                <option>'".$value['cuenta']."'</option>
                $cat= $conn->query("SELECT * FROM bancos");

                foreach ($cat as $key => $val) {
                    '<option value="'.$val["cuenta"].'">'.$val["cuenta"].'</option>';
                }
                </select></div>";
    echo '<tr>
    <td>'.$value['subsistema'].'</td>
    <td>'.$cajas.'</td>
    </tr>';
3
  • have you check print $cat is having all values or not ? and what is first forloop. foreach ($sql as $key => $value) { Jun 3, 2020 at 5:51
  • Where is fetch result function who fetch record ? while($row = $result->fetch_assoc()) { this line is missing. w3schools.com/php/php_mysql_select.asp Jun 3, 2020 at 6:16
  • Yes, the query is ok, what is not ok is that the select only shows me a result when it should show 10 Jun 3, 2020 at 13:29

1 Answer 1

0

Try this:

Replace your code with this.


$cat= $conn->query("SELECT * FROM bancos");
while($row = $cat->fetch_assoc()) {
 '<option value="'.$row["cuenta"].'">'.$row["cuenta"].'</option>';
}

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.