View Single Post
Old Dec 13th, 2006, 12:26 PM   #7
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
dynamic varible names are useful in many situations (like dynamicly generate html forms where you don't know how many fields there are and the field names come from a database or something like that), but most of the time, you can be making use of arrays, which require a bit less code. I have used dynamic varibles when working with excel sheets from php, makes life much easier (for sheet names etc, so you don't have to hard code them).

to use an array with an html form, simply name the field (lets say in this case a bunch of text fields) with a name like:

<input type=text name="text[]">
<input type=text name="text[]">
<input type=text name="text[]">


then, when your php script gets called, you can access the array like:


[PHP]<?PHP
for ($x=0; $x<3; $x++)
{
echo $_POST["text"][$x];
}
?>
[/PHP]

i know it's probably not what you are doing, but i thought you might like to know a little more information on how you can make use of arrays in php/html.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote