variable POST variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

variable POST variables

Post by rubberjohn »

can this method

Code: Select all

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

rj
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$_POST['prefix_'.$somevar]
:?:
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: variable POST variables

Post 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];
(#10850)
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post 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
Post Reply