hi, This is probably I really simple problem. I have a loop and want to create a new set of variables each time the loop completes. for ( $v=1; $_POST['rown'] >= $v; $v++ ) { if ($template == 5) { print" <tr> <input name=\"$dataa\" type=\"text\" size=\"40\"> <td bgcolor=\"#FFFFFF\"><input name=\"$dataa\" type=\"text\" size=\"40\"></td> <td bgcolor=\"#FFFFFF\"><input name=\"$datab\" type=\"text\" size=\"40\"></td> <td bgcolor=\"#FFFFFF\"><input name=\"$datac\" type=\"text\" size=\"40\"></td> <td bgcolor=\"#FFFFFF\"><input name=\"$datad\" type=\"text\" size=\"40\"></td> <td bgcolor=\"#FFFFFF\"><input name=\"$datae\" type=\"text\" size=\"40\"></td> </tr>"; } PHP: So that dataa in the next loop becomes dataa1, then dataa2 etc. Can I use a concatenate to do this?
this should do it for ( $v=1; $_POST['rown'] >= $v; $v++ ) { if ($template == 5) { echo " <tr> <input name='$dataa' type='text' size='40'> <td bgcolor='#FFFFFF'><input name='dataa{$v}' type='text' size='40'></td> <td bgcolor='#FFFFFF'><input name='datab{$v}' type='text' size='40'></td> <td bgcolor='#FFFFFF'><input name='datac{$v}' type='text' size='40'></td> <td bgcolor='#FFFFFF'><input name='datad{$v}' type='text' size='40'></td> <td bgcolor='#FFFFFF'><input name='datae{$v}' type='text' size='40'></td> </tr>"; } } PHP:
because you're already inside a string. The . is seen as plain text. {} tells PHP to find a variable to match the variable within (only 1) and not get confused with the other stuff that's plain string. You can leave the {} but it's faster and safer to use it.
Using the {} method, is it possible to get php to append a variable (with another variable) before it actually evaluates the variable? So if if have $data{$v} is in a loop. I would want the $v to evaluate first and that would lead to a string that was posted from a form. So that $data1 would be evaluated from the post ... $data2 $data3 etc.