Angelica Angelica - 4 years ago 111
SQL Question

How to insert data in a dropdown list

We managed to get the drop down list menu however, we are having difficulties getting the data from sql. So far, this is what we got.

<select>
<option id="">--Select jobscope--</option>

<?php

$con=mysqli_connect("host","user","password","database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$getIT = mysqli_query("SELECT job_title FROM `job_details`");
while($viewIT = mysqli_fetch_array($getIT)) {
}

?>
<option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option>

</select>

Answer Source

Shouldn't be like this ? with tag inside WHILE LOOP

   while($viewIT = mysql_fetch_array($getIT)) {
       <option id="<?php echo $viewIT['job_title']?>"<?php echo $viewIT['job_title']?></option>
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download