0

I am new to php I am trying to update classroom. In first loop i show all the classrooms in a table and it works fine and then i use another loop inside this loop which shows all the teacher against one row. mean if there is grade one then i try to show all the teacher at the end of the row in dropdown if admin want to change the teacher for this particular class. it shows all the teacher only in first row inside the dropdown but in second row it shows nothing. as you see in the picture first record in which classid is 22 this row have dropdown at the end it gives all the teacher in dropdown but all other rows down is empty picture to view the output. **

this is the code here

while ($row = mysqli_fetch_assoc($result)) {

        ?>
        <tr>
            <td><?php echo $row['id'] ?></td>
            <td>
                <?php echo $row['grade'] ?></td>
        



            <td>
                <form>
                    <select name="teacherDropdown" class="form-select bg-dark text-info">

                        <option selected>Select Teacher</option>
                        <?php
                            while ($mango = mysqli_fetch_assoc($getTeacher)) { ?>
                                <option value="<?php echo $mango['id'] ?>"><?php echo $mango['name'] ?></option>
                            <?php
                            }

                       ?>

                    </select>
                </form>
            </td>

        </tr>


        <?php
    }
    ?>
  • 1
    When you `fetch` the `$mango` result set, you "consume" the payload. You will need to save the data as an array before your first loop. (I'm hunting for a duplicate to close with -- you are not the first person to get tripped up by this.) For your information, you can either [`fetch_all()`](https://stackoverflow.com/a/47765007/2943403) or build up the db results with [a foreach loop without using `fetch()` calls](https://stackoverflow.com/a/66775416/2943403). – mickmackusa Oct 21 '22 at 06:11

0 Answers0