hi, i have a quick question regarding this. $rsvp1 through $rsvp5 is being passed on from the previous page by POST. value is either "1" or "". $g1 through $g5 is being passed on from the previous page by POST. value is either a string or "". $guest1 through $guest5 is created on current page. they are a lines of html code. now, i want to check $rsvp1 through $rsvp5 in a while loop to see what their values are...and then echo the appropriate things. $n1 is the counter. i want $rsvp.$n to be $rsvp1 if $n is 1 $guest.$n and $g.$n is the same idea. your help is much appreciated $n=1; while ( $n < 6 ) { if ($rsvp.$n == "1") { echo "<p>$guest.$n</p>"; } else { echo "<p>$g.$n is not attending</p>"; } $n++; } PHP:
I think you really need to redesign what you are doing. Your structure is awkward and would be far better suited to an array. You can do it through something like this - but you are better of redesigning what you are doing. $n = 1; while ($n < 6) { $var = "rsvp".$n; if($$var == 1) { $guest = "guest".$n; print "<p>".$$guest."</p>"; } else { $guest = "g".$n; print "<p>".$$guest." is not attending</p>"; } $n++; } PHP:
Another approach: echo '<p>', ${"guest{$n}"}, '</p>'; PHP: ... but yes, arrays are definitely the way to go.