mdhlme1 Posted April 17, 2007 Share Posted April 17, 2007 please can someone help me work out how to insert drop down answer boxes (like the oes you get in questionnaires) into my cong, i can't seem to get the coding right or make anything appear in the box. any help would be much appreciated. thank you. Link to comment https://forums.phpfreaks.com/topic/47418-drop-down-answer-boxes/ Share on other sites More sharing options...
AndyB Posted April 21, 2007 Share Posted April 21, 2007 If you want help with code you've written, you'll need to let someone see it. Link to comment https://forums.phpfreaks.com/topic/47418-drop-down-answer-boxes/#findComment-234895 Share on other sites More sharing options...
jchemie Posted April 21, 2007 Share Posted April 21, 2007 Well you should write a code that is something like this... <select name='select_name'> <?php foreach($option_values as $option_value) { echo "<option>".$option_value."</option>"; } ?> </select> This will give you all the options in a drop down menu. Thanks Jyot Link to comment https://forums.phpfreaks.com/topic/47418-drop-down-answer-boxes/#findComment-234897 Share on other sites More sharing options...
boo_lolly Posted April 21, 2007 Share Posted April 21, 2007 Well you should write a code that is something like this... <select name='select_name'> <?php foreach($option_values as $option_value) { echo "<option>".$option_value."</option>"; } ?> </select> This will give you all the options in a drop down menu. Thanks Jyot that may give the user a dropdown menu, but it will be useless because it has no value="". and, that will only work if the dropdown menu is populated from a hard-coded array. what if he wanted it populated from a database? this is what a dropdown menu should look like if it were populated from a database: <?php $db_conn = mysql_connect('xxx', 'xxx', 'xxx'); ((!$db_conn) ? (die('could not connect to mysql')) : ('')); mysql_select_db('your_database', $db_conn) OR die('could not connect to database'); $sql = " SELECT * FROM your_table "; $query = mysql_query($sql) OR die("[{$sql}]<br />\nCaused the following error: <i>". mysql_error() ."</i>\n"); echo "<form action=\"\" method=\"post\">\n"; echo "<select name=\"drop_down\">\n"; while($row = mysql_fetch_array($query)){ echo "<option value=\"{$row['column1']}\""; echo (($_POST['drop_down'] == $row['column1']) (' SELECTED') : (''); echo ">{$row['column2']}\n"; } echo "</select>"; echo "<input type=\"submit\" value=\"Submit\">\n"; echo "</form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/47418-drop-down-answer-boxes/#findComment-234913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.