hoopplaya4 Posted February 21, 2009 Share Posted February 21, 2009 Hi all, I've got a PHP form that has a "Multiple Select" box. Now, here's the thing, I want to pass multiple values through the form based on which options are selected. For example, here's my current code: <form> <select multiple style="width:300px; height:120px;" name="name[]" id="name"> <?php $sql = "SELECT usrID, usrFirst, usrLast, usrEmail"; $sql .= " FROM tblUsers"; $sql .= " WHERE usrActive = '1'"; $sql .= " ORDER BY usrFirst"; require("connection.php"); $rs=mysql_db_query($DBname,$sql,$link); while ($row=mysql_fetch_array($rs)){ print("<option value='" . $row["usrID"] . "'>"); print("" . $row["usrFirst"] . " " . $row["usrLast"] . "</option>\n"); } ?> </select> </form> As you can see, the "value" that's being passed is usrID. However, I'd also like to pass the field usrEmail (from my DB) as well. What is the best way to achieve this? Obviously, I don't want to make a separate "multiple select" box. Would I have to create a "hidden field" or something? Maybe this is something easy, and I'm overthinking. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
farkewie Posted February 21, 2009 Share Posted February 21, 2009 the same... To use the email its just $row['usrEmail '] Quote Link to comment Share on other sites More sharing options...
Maq Posted February 21, 2009 Share Posted February 21, 2009 Looks like you're not passing anything because your form does not have an action or method. How do you want to decide what value of usrEmail to pass through? Do you want to wait to see what option the user picks from the usrID SELECT menu first? I think I'm just a little confused as to exactly what you're trying to accomplish... Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted February 22, 2009 Author Share Posted February 22, 2009 Thanks for the replies guys. I'm sorry I was not specific enough: @farewei: I know I need to user $row['usrEmail '], my question is where would I put it? @Maq: First, I know I don't have the action (sorry for leaving it out, wanted to cut down the form). How do you want to decide what value of usrEmail to pass through? Do you want to wait to see what option the user picks from the usrID SELECT menu first? The answer to your second question is "Yes." Every user that is selected from the "multiple select box" has a usrID and a usrEmail. Right now, the form ONLY passes the usrID of the persons selected. However, I also want to pass the usrEmail of that selected person (option) as well. So, I'd like to know how I can go about passing both the usrID (which is already being passed) AND usrEmail. Should I separate it with a comma? <?php print("<option value='" . $row["usrID"] . "," . $row["usrEmail"] . "'>"); And then split it up later? Or is there just an easier way to pass the data as two separate fields? Please let me know if I need to be more specific. Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted February 22, 2009 Author Share Posted February 22, 2009 Hmm...anyone? (Sorry if I'm being impatient!) Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 22, 2009 Share Posted February 22, 2009 you need a method= (get or post) you can have all of $sql in one quote set I would also personally use: echo "<option value='$row[usrID]'>$row[usrFirst] $row[usrLast]</option>"; On the reception page you can do a bcc by doing a for each if multiple options are selected then query the e-mail address, and send it to the recipient. Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted February 22, 2009 Author Share Posted February 22, 2009 On the reception page you can do a bcc by doing a for each if multiple options are selected then query the e-mail address, and send it to the recipient. Ok, thanks. So, let's say I pass an array of three usrIDs (32, 35, and 36). (On the next page, it'd obviously be $_POST["name"]). So, on the next page, what would my MySQL SELECT query look like to grab all email addresses from the array? Quote Link to comment Share on other sites More sharing options...
Q695 Posted February 22, 2009 Share Posted February 22, 2009 The select would be below the insert on the page. 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.