Jump to content

[SOLVED] How to cary a variable from a value


Monk3h

Recommended Posts

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. :)

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])) {

?>

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.
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.