Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenation maybe??

Status
Not open for further replies.

MatthewP

Programmer
Jan 16, 2001
176
GB
HI,

A form submits a name value pair, name=item500 value=20.

I can reference this in my script with $item500 to get the value.

If I don't know the name of the form element (ie - it starts with 'item' followed by a number I don't know) - how can I reference this?

I know what the number will be, but I need to do it as a variable - eg the number of the item is stored in $number.

What I need to do is get the value of item500, as item$number, but I have to reference it as a string, so I have to do $value$item = $item$number - which obviously doesn't work. I guess I have to concatenate this first, but how?

Thanks in advance, this has been doing my head in for 4 hours now!!

Matt.
 
You can access all posted variables from the $HTTP_POST_VARS collection, (unless you have turned off support for tracking server environment vars in your php.ini)

The example below prints out all posted variables from any form that uses this script as the ACTION:

I'm sure you can see from here how easy it will be to get any $key name that begins with "item", and use substr() or regular expressions to get the remaining value. Good luck.

<?php
while(list($key,$value) = each($HTTP_POST_VARS)) {
if(is_array($value)) {
while(list($key2,$value2)=each($value)) {
echo &quot;array $key: $key2 -> $value2<BR>&quot;;
}
} else {
echo &quot;$key -> $value<BR>&quot;;
}
}
?>
 
Thanks - that's what I should have done in the first place I guess.. Doh!

Cheers,

Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top