in a project, I define a text-block like e.g.:
$test = '<div>Name'.$i.': <input type="text" name="name'.$i.'" value="'.$_POST['name'.$i].'" /></div>';
The text-block is then used within a for-loop like:
$_POST['name1'] = 'Max';
for($i=0;$i<3;$i++){
$test = '<div>Name'.$i.': <input type="text" name="name'.$i.'" value="'.$_POST['name'.$i].'" /></div>';
echo $test;
}
This produces the desired result:
<div>Name0: <input type="text" name="name0" value=""></div>
<div>Name1: <input type="text" name="name1" value="Max"></div>
<div>Name2: <input type="text" name="name2" value=""></div>
Now, I would like to get the text-block $test from a database and use it within the loop but I cannot figure out how to modify the variables $i to work.
Actually, it is like:
$_POST['name1'] = 'Max';
$string = '<div>Name'.$i.': <input type="text" name="name'.$i.'" value="'.$_POST['name'.$i].'" /></div>';
for($i=0;$i<3;$i++){
$test = $string;
echo $test;
}
Can anybody give me a hint on how to achieve this?