Hi
Can anyone think of a way to write this as a loop that loops 4 times instead of like the way I have it.
<? //Person1 $name1 = $POST['Name1']; $add1 = $POST['Add1']; $city1 = $POST['City1']; $prov1 = $POST['Prov1']; $zip1 = $POST['Zip1']; $email1 = $POST['Email1']; $home1 = $POST['Home1']; $work1 = $POST['Work1']; $cell1 = $POST['Cell1']; //Person2 $name2 = $POST['Name2']; $add2 = $POST['Add2']; $city2 = $POST['City2']; $prov2 = $POST['Prov2']; $zip2 = $POST['Zip2']; $email2 = $POST['Email2']; $home2 = $POST['Home2']; $work2 = $POST['Work2']; $cell2 = $POST['Cell2']; //Person3 $name3 = $POST['Name3']; $add3 = $POST['Add3']; $city3 = $POST['City3']; $prov3 = $POST['Prov3']; $zip3 = $POST['Zip3']; $email3 = $POST['Email3']; $home3 = $POST['Home3']; $work3 = $POST['Work3']; $cell3 = $POST['Cell3']; //Person4 $name4 = $POST['Name4']; $add14 = $POST['Add4']; $city4 = $POST['City4']; $prov4 = $POST['Prov4']; $zip4 = $POST['Zip4']; $email4 = $POST['Email4']; $home4 = $POST['Home4']; $work4 = $POST['Work4']; $cell4 = $POST['Cell4']; ?>
I think it would be something along the lines of this but it didn't work
<? for($i = 1; $i >= 4; $i++){ $name.$i = $_GET['Name'.$i]; } ?>
Thanks for any help
-Mark
Hi,
think that this way it should work:
<? for($i = 1; $i >= 4; $i++){ $name[$i] = $_GET['Name'.$i]; } ?>
I think this is what you're trying to do:
${'name' . $i} = $_GET['Name' . $i];
Edit: Although using arrays, as in leatherback's example, is the better way to do it. But never use short opening tags.
Please use the forum PHP tags (via the button that says "PHP").
works great thanks
Heres something else:
what if if had an array like so
$stats = array (1 => 'name', 'add', 'city', 'prov', 'zip', 'home', 'work', 'cell');
how would ig et those values into the loop?
Something like this...
for($i = 1; $i >= 4; $i++){ $stats = array (1 => 'name', 'add', 'city', 'prov', 'zip', 'home', 'work', 'cell'); foreach($stats as $value) { if(isset($_POST[$value.$i])){ $value.$i = $_POST[$value.$i]; }else{ $value.$i = ""; } } }
But of course that doesn't work
My last post shows you how to make it work.