Page 1 of 1

variable POST variables

Posted: Wed Apr 12, 2006 2:14 pm
by rubberjohn
can this method

Code: Select all

${"variable". $counter}
be used for $_POST variables?

rj

Posted: Wed Apr 12, 2006 2:15 pm
by John Cartwright

Code: Select all

$_POST['prefix_'.$somevar]
:?:

Posted: Wed Apr 12, 2006 2:23 pm
by rubberjohn
no ive tried that - presumably the _ also has to be included in the original name (before it is POSTed) - or is that needed to make it work?

Re: variable POST variables

Posted: Wed Apr 12, 2006 4:59 pm
by Christopher
You can access the element of any array with a variable, such as:

Code: Select all

$variable = 'foo';
$counter = 42;
$key = $variable . $counter;
echo $_POST[$key];

Posted: Wed Apr 12, 2006 5:26 pm
by rubberjohn
cheers for the reply

yeah it would but what i am trying to do is use a set of linked lists that display dynamically

the linked list names are concatenated with a number - the number being the number of previous lists + 1 but on each page I need to check if that linked list has been POSTed

so the linked list would be declared like this:-

Code: Select all

${"sub_topic". $branch_count}  = '<select name="sub_topic'. $branch_count.'" onChange="this.form.submit()">';
and then to check if a value from this list has been submitted i need to check the POST vars - something along the lines of

Code: Select all

if(isset($_POST['sub_topic'. $branch_count])){

...

}
but that doesn't work and ive tried all sorts of combinations of that - i would have thought this was possible but maybe not

rj