searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 ok, it is working properly, but how do I put in my drop down menu for the event, there could be a total of 8 events to choose from. You made it a text box, how do you make it a drop down menu.......I could try it myself, but with all the things you added, I don't really know whats what and I don't wanna mess it up. Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1206966 Share on other sites More sharing options...
searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 also I don't need the query to echo any more, could you take that off, I don't know what is what for I havn't ever seen this type of code. by the way, the events are $title(1-. Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1206968 Share on other sites More sharing options...
searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 anything? Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207044 Share on other sites More sharing options...
wildteen88 Posted April 27, 2011 Share Posted April 27, 2011 To display a dropdown menu change <?php for($i = 1; $i <= 8; $i++): $titleNum = "title$i"; $titleText = $$titleNum; if(!empty($titleText)): ?> <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" /> <?php endif; endfor; ?> To <select name="title"> <?php for($i = 1; $i <= 8; $i++): $title= ${"title$i"}; ?> <option value="<?php echo $$title; ?>"><?php echo $$title; ?>" /> <?php endfor; ?> </select> However now that you have the drop down menu. We now have a problem. A drop menu can only have one name and submits the chosen values. It doesn't submit the unchosen ones, so how are you supposed to add the chosen title into the corresponding title field? You're better of getting rid of the fields title1-8 in your events table and have a single field (call it event_title) for storing the chosen event title. If you go this route then change for($i = 1; $i <= 8; $i++) ${"title$i"} = isset($_POST["title$i"]) ? $_POST["title$i"] : ''; $query_values[] = "('$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')"; } $query = "insert into Events (\n\ttitle1, title2, title3, title4, title5, title6, title7, title8, userid, name, eventid, event, email, \n\t" . To for($i = 1; $i <= 8; $i++) $event_title = $_POST["title"]); $query_values[] = "('$event_title', '$userid', '$name','$eventid', '$event', '$email', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', 'quick', '$id')"; } $query = "insert into Events (\n\event_title, userid, name, eventid, event, email, \n\t" . also I don't need the query to echo any more, could you take that off, I don't know what is what for I havn't ever seen this type of code Either comment out or remove this line echo "Generated query: <pre>$query</pre>"; I only added that for debug purposes. So I could see how the query was being generated. I havn't ever seen this type of code The query inserts multiple records at once. Rather than inserting a new record one by one. Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207058 Share on other sites More sharing options...
searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 ok, I see what you are saying, but a person can be registered for more than one event. I should actually change the query to a replace into though for this way to work with the drop down menu. that way it will update every time I were to register someone for like title1 then for title2 so that way each person can be registered for multiple events if available. how do I do this so that it updates multiples instead of one at a time. Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207061 Share on other sites More sharing options...
wildteen88 Posted April 27, 2011 Share Posted April 27, 2011 So you want the script to change the event title if they are already assigned to an event? Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207068 Share on other sites More sharing options...
searls03 Posted April 27, 2011 Author Share Posted April 27, 2011 no, I want the if !empty back in there like it was before you changed it. this way I can specify ecent people are registered for in one row. Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207071 Share on other sites More sharing options...
wildteen88 Posted April 27, 2011 Share Posted April 27, 2011 Then replace code <?php for($i = 1; $i <= 8; $i++): $titleNum = "title$i"; $titleText = $$titleNum; if(!empty($titleText)): ?> <input type="text" name="<?php echo $titleNum; ?>" value="<?php echo $titleText; ?>" /> <?php endif; endfor; ?> With your old code <?php if (!empty($title1)) { echo "<select name=\"title1\" id=\"title1\"> <option value=\"$title1\">$title1</option>";} if (!empty($title2)) { echo "<select name=\"title2\" id=\"title1\"> <option value=\"$title2\">$title2</option>";} if (!empty($title3)) { echo "<select name=\"title3\" id=\"title1\"> <option value=\"$title3\">$title3</option>";} if (!empty($title4)) { echo "<select name=\"title4\" id=\"title1\"> <option value=\"$title4\">$title4</option>";} if (!empty($title5)) { echo "<select name=\"title5\" id=\"title1\"> <option value=\"$title5\">$title5</option>";} if (!empty($title6)) { echo "<select name=\"title6\" id=\"title6\"> <option value=\"$title6\">$title6</option>";} if (!empty($title7)) { echo "<select name=\"title7\" id=\"title1\"> <option value=\"$title7\">$title7</option>";} if (!empty($title8)) { echo "<select name=\"title8\" id=\"title1\"> <option value=\"$title8\">$title8</option>";} ?> </select> Which just displays separate menus for each event title that isn't empty Quote Link to comment https://forums.phpfreaks.com/topic/234548-problems-with-arrays/page/2/#findComment-1207081 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.