Monk3h Posted March 18, 2009 Share Posted March 18, 2009 I have created a script to bring back some info from my database in the form of a drop down menu. i did this using an array. <option value='$ability[id]'>$ability[name]</option> $ability[name] obviously prints the name of each ability into a drop down menu (i have removed to array to make this quicker). the value is the abilitys ID, this is what i want to carry forward. there is a submit button after the drop down menu. what i want to do is once the ability name is selected i would like to be able to print the ability id. how would i do this out of the arrey? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted March 18, 2009 Share Posted March 18, 2009 Well it should be coming from $_POST right, so we have to know what the ID that is chosen was; obviously dumping the var would work but not if you have other $_POST vars which you most likely do, so your best bet IMO is to compare $_POST to the array again kind of like this. <?php if(isset($_POST[$ability[id])) { ?> Quote Link to comment Share on other sites More sharing options...
WolfRage Posted March 18, 2009 Share Posted March 18, 2009 So twice now I have tried to post with out success. What i meant to say is you need to include name in your option. <?php echo "<option name='ability' value='$ability[id]'>$ability[name]</option>"; ?> then you will be able to echo that option like so. <?php echo $_POST['ability']; //this will contian the assigned value from $ability[id] //of course do not forget to screen for security. ?> Quote Link to comment Share on other sites More sharing options...
Monk3h Posted March 19, 2009 Author Share Posted March 19, 2009 Worked!! Thanks mate, LEGEND! 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.