niche Posted May 29, 2009 Share Posted May 29, 2009 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 More sharing options...
Synook Posted May 29, 2009 Share Posted May 29, 2009 you would use htmlspecialchars() if you ididn't want the browser to parse the <option> tags. Link to comment Share on other sites More sharing options...
niche Posted May 29, 2009 Author Share Posted May 29, 2009 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 More sharing options...
smerny Posted May 29, 2009 Share Posted May 29, 2009 <?php=$options?>try<?phpecho $options;?> Link to comment Share on other sites More sharing options...
smerny Posted May 29, 2009 Share Posted May 29, 2009 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 More sharing options...
niche Posted May 29, 2009 Author Share Posted May 29, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.