Jump to content

Problem With Drop Down Options From Mysql Database


niche

Recommended Posts

This code produces a drop down box, but no options. I thought the problem would be solved with htmlspecialchars(). Please help. Thanks.<?php$sql="SELECT department_id, name FROM department";$result=mysql_query($sql);$options="";while ($row=mysql_fetch_array($result)) { $thing=$row["name"]; $options.=htmlspecialchars("<OPTION>".$thing."</OPTION>");}?><SELECT NAME="name"><OPTION>Choose One</OPTION><?php=$options?></SELECT>

Link to comment
Share on other sites

:) you would use htmlspecialchars() if you ididn't want the browser to parse the <option> tags.
Link to comment
Share on other sites

It didn't work without the htmlspecialchars() either. Is the problem in my php or html or both?

Link to comment
Share on other sites

this is how i would do it though

<SELECT name="name"><?php$sql="SELECT department_id, name FROM department";$result=mysql_query($sql);while ($row=mysql_fetch_array($result)) {$thing=$row["name"];echo "<OPTION>".$thing."</OPTION>";}?></SELECT>

Link to comment
Share on other sites

We're pretty close to each other's thinking. Here's what I'm using:<?php$sql = mysql_query("SELECT department_id, name FROM department");$options = '';echo '<select name="name"><option>CHOOSE ONE</option>';while($row = mysql_fetch_array($sql)) {$id = $row['department_id'];$thing = $row['name'];echo '<option value='.$id.'>'.$thing.'</option>';}echo '</select>';?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...