MrFahad
asked on
How to create a dynamic drop down menu from a feild in my database
Hello, i have a database for real estate website. i want to want to make a dynamic drop-down menu that will show the records from a feild in my database's table.
the feild name is PropertyName.
Thank you
the feild name is PropertyName.
Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Penguin, I think you forgot closing the </option> in your code...
ASKER
Penguin it is only display 1st letter of the PropertyName
ASKER
What's the problem with Penguin's code? Apart that there's a missing >?
echo '<SELECT>';
$result = mysql_query('SELECT PropertyName FROM tablename');
foreach (mysql_fetch_array($result) as $property)
{
echo '<option value="'.$property['PropertyName'].'">'.$property['PropertyName'].'</option>';
}
echo '</SELECT>';
@striker46 : Thanks for the missing >
@MrFahad : This piece of code should display exacly what is in the field of the database. Just to make sure we are talking about a field not a row?
@MrFahad : This piece of code should display exacly what is in the field of the database. Just to make sure we are talking about a field not a row?
ASKER
no it's the row ( record )
here is the screen shot of my DB i pointed with any arrow what i want to disply
ss2.jpg
here is the screen shot of my DB i pointed with any arrow what i want to disply
ss2.jpg
Could you please post the outputted HTML code of the dropdown menu? From the first screenshot, with the fetched results.
ASKER
<label for="PropertyName"><em>Ple ase enter a unique property name that the customer bought:</em></label>
<SELECT><option value="9">9</option><optio n value="9">9</option></SELE CT>
<SELECT><option value="9">9</option><optio
That's weird, it retrievied twice a same row? I see the code has two options "9" but in the table you showed in the 2nd screenshot there's just 1 row, isn't there?
Try the code below
Try the code below
<?php
$sql = "SELECT PropertyName
FROM properties;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row["PropertyName"].'">'.$row["PropertyName"].'</option>';
}
?>
Sorry, forgot the <SELECT>
echo "<SELECT>";
$sql = "SELECT PropertyName
FROM properties;
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row["PropertyName"].'">'.$row["PropertyName"].'</option>';
}
echo "</SELECT>";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked Great Striker46, I'm also giving points for penguin Thanks guys great work.