I have made a script that functions perfectly within normal parameters, However as the script became a little more dynamic I noticed a problem. Although the functionality is there and works perfectly fine, when viewing the html source the elements have completely disappeared. This only occurred when I generated a input field within a foreach().
Heres the code:
If I take the foreach out it's fine and works the same but with the html tags inside. The issue is I need the foreach as I will cycle through the posts. This is far from a perfect script for the type of job I aim to do but sadly it's the only way I can achieve what I want to do for this system.
Heres the code:
PHP:
foreach($_POST as $k => $v){
if($v == 'present'){
$pre = 'percentage_';
$post = $pre.$k;
$val[$k] = $_POST[$post];
$sql = mysql_query("SELECT * FROM table WHERE element = '$k'");
$max = mysql_num_rows($sql);
$first = mysql_result($sql, 0, 'element');
for($i = 0; $i<$max; $i++){
$element = mysql_result($sql, $i, 'sub_element');
$element = str_replace('_', ' ',$element);
$current = mysql_result($sql, $i, 'element');
if($i == 0){
echo "<fieldset><legend><b>".$current." : ".$val[$k]."%</b></legend>";
echo $element."<input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"present\"> Yes <input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"absent\" checked> No <input type=\"text\" name=\"percentage_".mysql_result($sql,$i,'sub_element')."\" />% of EQF<br />";
}
if($i>0){
$previous = mysql_result($sql, $i-1, 'element');
if($current == $previous){
echo $element."<input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"present\"> Yes <input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"absent\" checked> No <input type=\"text\" name=\"percentage_".mysql_result($sql,$i,'sub_element')."\" />% of EQF<br />";
}
else{
echo "</fieldset><fieldset><legend><b>".$current."</b></legend>";
echo $element."<input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"present\"> Yes <input type=\"radio\" name=\"".mysql_result($sql,$i,'sub_element')."\" value=\"absent\" checked> No <input type=\"text\" name=\"percentage_".mysql_result($sql,$i,'sub_element')."\" />% of EQF<br />";
}
}
}
}
}
?>
If I take the foreach out it's fine and works the same but with the html tags inside. The issue is I need the foreach as I will cycle through the posts. This is far from a perfect script for the type of job I aim to do but sadly it's the only way I can achieve what I want to do for this system.