woodplease Posted September 2, 2010 Share Posted September 2, 2010 i'm trying to print out values from a table into a drop down box, but my code doesnt seem to work. when i test it, there are no values in the drop down box. if someone could find the problem, that would be great. <form name="add_sub_section" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>"> Sub Section Name <input type="text" name="sub_section_title" maxlength="200" /><br/><br/> Sub Section desc <textarea name="sub_section_desc" rows="4" columns="30" /></textarea><br/><br/> SECTION <?php $list = "SELECT section_title FROM section_main"; echo "<select name='section_title'>"; while ($a = mysql_fetch_row($list)) { for ($j = 0; $j < mysql_num_fields($list); $j++) { echo "<option value=". $a[$j] . ">". $a[$j] . "</option>"; } } echo "</select>"; ?> <br/><br/> <input type="submit" name="submit" value="Add Section"/> </form> the connection to the table works, so i havnt put that code in. there's no formatting for the html yet, i just want to get the php working first Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 2, 2010 Share Posted September 2, 2010 You are not running the query. Odd, since I would think you would get an error when trying to run mysql_fetch_row() on a string. Plus, the logic of reading the records is all wrong. Try this <?php $query = "SELECT section_title FROM section_main"; $result = mysql_query($query) or die(mysql_error()); $titleOptions = ''; while ($row = mysql_fetch_assoc($query)) { $titleOptions .= "<option value=\"{$row['section_title']}\">{$row['section_title']}</option>\n"; } ?> <form name="add_sub_section" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Sub Section Name <input type="text" name="sub_section_title" maxlength="200" /> <br /><br /> Sub Section desc <textarea name="sub_section_desc" rows="4" columns="30" /></textarea> <br /><br /> SECTION <select name="section_title"> <?php echo $titleOptions; ?> </select> <br/><br/> <input type="submit" name="submit" value="Add Section" /> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.