How to append <option>
in jQuery with a value from database. For example:
<?php
$sql = "query from database";
$result = mysqli_query($conn, $sql);
if (!$result)
{
die(mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
$name = $row['name'];
$id = $row['id'];
}
}
?>
<select name="selector" id="selector">
<option value="0">Make Selection</option>
</select>
I want to append the value from database to the select
box. I tried with below codes but the result is blank.
$('#selector').find('option').append('<option value="<?php echo $id; ?>"><?php echo $name;?>');