Page 1 of 1

Variables (String combination ?)

Posted: Tue Feb 10, 2004 9:25 am
by raymedia
Hi guys,

I currently have a form that have few text fields in it. After I submit the form, I would like to manipulate the field data..

For example I have

Code: Select all

<form>
<input type="text" size=40 name="xxx1" value="1">
<input type="text" size=40 name="xxx2" value="2">
<input type="text" size=40 name="xxx3" value="3">
</form>
And would like to print the data

Code: Select all

for ($i = 1; $i < 4; $i++)&#123;
	// here I want to know how to call the variables.
               // I tried this, but its not working.
               // echo ("$" . "xxx". $i);
&#125;
Thank you a lot for your time

Posted: Tue Feb 10, 2004 9:30 am
by twigletmac
Assuming that the form's method is POST, you could do:

Code: Select all

for ($i = 1; $i < 4; $i++){
    echo $_POST['xxx'.$i];
}
if you were wanting to send the form via the GET method you should change $_POST for $_GET.

Mac

Posted: Tue Feb 10, 2004 9:35 am
by raymedia
Thank you for that...really aprreciate it. If you don't mid..another quick question..if its not parsed from forms, how to build/ call these variables. For example,

Code: Select all

$xxx1 = "123";
$xxx2 = "abc";
$xxx3 = "1a2";
		
for ($i = 1; $i < 4; $i++)&#123;
      echo ("$xxx".$i);
&#125;

Posted: Tue Feb 10, 2004 9:53 am
by twigletmac
To do the same using variable variables:

Code: Select all

for ($i = 1; $i < 4; $i++) {
	echo ${'xxx'.$i};
}
Mac