I have a drop-down list in HTML, where the contents need to load from my MySQL DB using PHP.
I tried like the following; but no option is loading.
<strong> Select Data </strong>
<select name="data1">
<option value=""> NONE </option>
<?php
$dd_res=mysql_query("Select relation FROM relation_names");
while($r=mysql_fetch_row($dd_res))
{
echo "<option value='$r[0]'> $r[0] </option>";
}
?>
</select>
Also i tried like this:
$q="SELECT DISTINCT *relation FROM relation_names";
$rs=mysql_query($q);
if($rs && mysql_num_rows($rs))
{
while($rd=mysql_fetch_object($rs))
{
echo("<option value='$rd->id'>$rd->name</option>");
}
}
But I don't know why these are not working, kindly help me.
i tried the code below as per comment. but option names are not diplaying.