Looping

How can i get this to loop properly?


<?php
include 'connect.php'; 
                
                $result = mysql_query("SELECT * FROM Table "); 
                $i = 0;
                while($r=mysql_fetch_array($result)){
                    $title=$r["title"];
                    $testimonial=$r["testimonial"];
                    $id=$r["id"];
                
?>

<?php
                function $i format_html($testimonial){
                  $testimonial = "<p>" . str_replace("
", "<br/>", $testimonial) . "";
                  $testimonial = "" . str_replace("<br/><br/>", "</p><p>", $testimonial) . "";
                  $testimonial = "" . str_replace("**", "<img src='images/icon.gif' width='9' height='9' border='0'>", $testimonial) . "";
                  $testimonial = "" . str_replace("[pdf]", "<img src='images/icon_pdf.gif' width='20' height='20' border='0'>", $testimonial) . "";
                  $testimonial = "" . str_replace("---", "<div class='line' /><br /></div>", $testimonial) . "";
                  return "" . str_replace("<br/><li>", "<li>", $testimonial) . "";
                 }
                echo $i format_html("$testimonial");
                ?>
<?php
i++;
 } 
?>