mtgriffiths Posted April 16, 2008 Share Posted April 16, 2008 Hi All, I have created a dynamic drop down box where the value is a teams id and the information shown in the box is the teams name. I also need to pass over the teams email address to another page when the submit button is pressed. Is there anyway to do this? Using hidden select fields or something? Thanks in advance Matthew Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/ Share on other sites More sharing options...
unidox Posted April 16, 2008 Share Posted April 16, 2008 Code? Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518698 Share on other sites More sharing options...
pocobueno1388 Posted April 16, 2008 Share Posted April 16, 2008 You could use a delimiter for the select boxes value, that way you can store the ID and email. Like this: <option value="ID-Email">Teams Name</option> Then on the next page, you can just use the explode() function to separate the ID and email by the hyphen. Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518701 Share on other sites More sharing options...
mtgriffiths Posted April 16, 2008 Author Share Posted April 16, 2008 The code i am using is: $Query = mysql_query("select * from users WHERE League = '$League'") or die(mysql_error()); <select name="Team_Name"> <option selected="selected">Team Name</option> <?php while ($Row = mysql_fetch_array($Query)){ ?> <option value=<?php echo $Row["Team_Name"]; ?>> <?php echo $Row["Team_Name"]; ?> </option> <?php } ?> </select> pocobueno1388 - how would i go about doing that? I havent done anything like that in the past. Thanks EDIT - I have the teams name passing over now. The information is going to be used inside an email. I need the teams name to be posted over to include in the email but i need the email address to specify where the email is going Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518709 Share on other sites More sharing options...
unidox Posted April 16, 2008 Share Posted April 16, 2008 In that case I would use a hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518723 Share on other sites More sharing options...
benphp Posted April 16, 2008 Share Posted April 16, 2008 <?php print "<form>"; $Query = mysql_query("select Team_Name, teamID from users WHERE League = '$League'") or die(mysql_error()); while ($Row = mysql_fetch_array($Query)){ $teamName = $Row[0]; $teamID = $Row[1]; $teamDropdown = "<option value=\"$teamID\">$teamName</option>"; } print " <select name=\"Team_Name\"> <option selected=\"selected\">Team Name</option> $teamDropdown </select> <input type=\"hidden\" name=\"email\" value=\"$email\"> </form> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518736 Share on other sites More sharing options...
mtgriffiths Posted April 16, 2008 Author Share Posted April 16, 2008 Thanks for all the replies. I have tried what was suggested but still no joy. I am trying something like this: <select name="Team_Name"> <?php while ($Row = mysql_fetch_array($Query)){ $Name = $Row["Team_Name"]; $Email = $Row["email"];?> <option value=<?php echo $Name; ?>> <?php echo $Name; ?> </option> <?php } ?> </select> <input type="hidden" name="Team1_ID" value="<?php echo $Email; ?>" /> This prints out the teams names in the drop down box but does not pass over the value of $Email....as it is out of the loop would this make the value blank? Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518767 Share on other sites More sharing options...
benphp Posted April 16, 2008 Share Posted April 16, 2008 I don't think I understand then. Do you want a form that has a hidden field that changes to the correlating Email address when you select a Team? So you pick a team from the dropdown, you want that team's email address to populate a hidden field? And if you select a different Team, you want that team's address in the hidden email field. Is that it? If so, you'll need to use javascript, unless you want to query the page every time someone selects a different team. And I suspect you'll need to create an array with teamID and Email to populate the hidden field. It would be easier to pass the teamID over to a SQL page, which can fetch the selected team's email address there before updating/deleting. Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518779 Share on other sites More sharing options...
mtgriffiths Posted April 16, 2008 Author Share Posted April 16, 2008 Yes, depending on the team selected i would like the hidden email field to be populated by their email address from the query. I cant see why the hidden field cannot be populated by the email address. I have populated hidden fields in the past using while loops. As there is select i dont know how to do it...driving me crazy. There are 2 bits of information that i need passed over to the following page from the select box. Those are the selected teams name and selected teams email address. any ideas anyone? Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518785 Share on other sites More sharing options...
benphp Posted April 16, 2008 Share Posted April 16, 2008 Option 1: When you select a team from the dropdown, you need to requery. Set javascript to submit form onChange and requery the page based on the selection. Option 2: Submit the page to a SQL page, which selects the desired team's email address, then do your SQL updates. Option 3: Use javascript to change the hidden field to the selected team's email address. Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-518796 Share on other sites More sharing options...
benphp Posted April 17, 2008 Share Posted April 17, 2008 Fourth option: <?php $teamName = $_POST['Team_Name']; list($tName, $tEmail) = split(",", $teamName); ?> <select name="Team_Name[]"> <?php while ($Row = mysql_fetch_array($Query)){ $Name = $Row["Team_Name"]; $Email = $Row["email"]; print "<option value=\"$Name,$Email\" >$Name</option>"; ?> </select> <?php print "<p>You selected ClientName: $tName (email: $tEmail)</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/101415-help-me-please/#findComment-519133 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.