seveneleven Posted June 24, 2010 Share Posted June 24, 2010 Hi, I am trying to build a cascading select menu. I have it working except for this part. The very first menu should list 4 different events. When I test the page it only displays the first one. The code I am using is below. <select name="event" onChange="autoSubmit();"> <option value="null"></option> <option value=" echo $row_events['event_id']; ?>" <?php if($event == $row_events['event_id']) echo " selected"; ?>><?php echo $row_events['event_no']; ?></option> </select> Any help is appreciated. Thank you Link to comment https://forums.phpfreaks.com/topic/205804-dynamic-select-menu-problem/ Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 It's doing exactly as it should do, according to the code. There are 2 <option></option> tags, one has a NULL value, the other has what appears to be data from a DB query, however, the second <option> needs a PHP open tag before the first echo() statement, and I believe the technically proper html syntax to preselect an <option> item is selected="selected", rather than just "selected". Link to comment https://forums.phpfreaks.com/topic/205804-dynamic-select-menu-problem/#findComment-1076937 Share on other sites More sharing options...
seveneleven Posted June 25, 2010 Author Share Posted June 25, 2010 Hi thank you for your help. The database column that I am calling has 4 entries. How do I get it to display all 4 and not just the first? Here is more code I have tried where I use the query inside the php tags. Results are parse errors, and I cant find what it is. select name="event" onChange="autoSubmit();"> <option value="null"></option> <option value=" <?PHP $sql="SELECT events.event_id, events.event_no FROM events WHERE events.event_date >= current_date"; $event = mysql_query($sql,$conn); echo $row_event['event_id']; if($event == $row_event['event_id']) echo {"selected"};> echo "{$row_event['event_no']}; </option>"?> </select> Link to comment https://forums.phpfreaks.com/topic/205804-dynamic-select-menu-problem/#findComment-1076972 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 You would need to echo the data from within a loop. I obviously haven't tested this, but give it a try. <option value="null"></option> <?php $sql="SELECT events.event_id, events.event_no FROM events WHERE events.event_date >= current_date"; $event = mysql_query($sql,$conn); while( $array = mysql_fetch_assoc($event) ) { echo "<option value=\"" . $array['event_id']"; if( $event == $array['event_id']) { echo "selected=\"selected\""; } echo ">" . $array['event_no'] . "</option>\n" } echo "</select>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/205804-dynamic-select-menu-problem/#findComment-1076982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.