PHP issue, html disappearing in source.

Associate
Joined
4 Mar 2007
Posts
315
Location
United Kingdom
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:

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.
 
Maybe im not understanding your problem correctly, but you said that the script works fine.

Your just concerned that your HTML in the source has "disappeared"?
But it still works as it should?
Could all the HTML just be on the same line witn no linefeeds?

If your script is working fine still, then the HTML must be in the source somewhere?
 
Back
Top Bottom