0

so, this is my first time trying dynamic drop down list. So, i've copied the code from my teachers, and in my case, the option values dont shows up. this is my code :

<?php
    $sql = "SELECT * FROM soal;";
    $query = mysqli_query($connection, $sql);
?>
<div id="container">
    <form action= ""method="">
        <select name= "id_soal">
            <option>-- Pilih Soal --</option>
            <?php if (mysqli_num_rows($sql) >0){?>
                <?php while ($row=mysql_fetch_array($sql)) {?>
                    <option><?php echo $row['soal_id']?> </option>
                <?php } ?>
            <?php } ?>
        </select>
        <input type = "submit" value= "OK" name="ok_submit"/>
    </form>
</div>

this is my output : drop down list output

and of course this is my db : database picture

please tell me where o i get it wrong?T-T

so, from @user3783243 advise, i changed the code to be like this :

<?php
    $sql = "SELECT * FROM soal;";
    $query = mysqli_query($connection, $sql);
?>
<div id="container">
    <form action= ""method="">
        <select name= "id_soal">
            <option>-- Pilih Soal --</option>
            <?php if (mysqli_num_rows($query) >0){?>
                <?php while ($row=mysql_fetch_array($query)) {?>
                    <option><?php echo $row['soal_id']?> </option>
                <?php } ?>
            <?php } ?>
        </select>
        <input type = "submit" value= "OK" name="ok_submit"/>
    </form>
</div>

but still, the opetions dont show up.. T-T.. or,did i changed it wrong? because i'm literally new with programming.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

0
while ($row=mysql_fetch_array($query))

please change your code to:

while ($row=mysqli_fetch_array($query))
user3783243
  • 5,368
  • 5
  • 22
  • 41
Vidya
  • 66
  • 7
  • thank you... i dont know tht i missed it T-T .. – Ayu Hapsari Oct 28 '19 at 08:15
  • 1
    Please don't post answers only pointing out a typographical issue or a missing character. Such answers are unlikely to help future visitors since they are specific to OP's code. Instead, flag or vote to close the question as off-topic as per the [help/on-topic]. – Dharman Oct 28 '19 at 10:13