i am working on creating php templates for an application, but i am not understanding how to cover while loop in templates, my code is as follow, that is not right and of course not working at all, it is being posted just for example. Please any body give me an idea that how it can be implemented,

<?php
require_once("temp-test.php");
mysql_connect("localhost", "root","")or die("cannot connect"); 
mysql_select_db("test") or die("cannot select DB");

$sql="SELECT rid,tid,name FROM reply";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$rid=$row[rid];
$tid=$row[tid];
$name=$row[name];
}
?>

the temp-test.php file as follow

<html>
<head>
<title>template</title>
</head>
<body>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="360" height="100">
 <tr><td width="358" height="100">
<p style="margin-left: 10; margin-top: 0; margin-bottom: 5"><font face="Segoe UI">Reply ID:<font color="#DA251D">
<?php echo "$rid";?></font></font></p>

<p style="margin-left: 10; margin-top: 0; margin-bottom: 5"><font face="Segoe UI">Topic ID:<font color="#DA251D"><?php echo "$tid";?></font></font></p>

<p style="margin-left: 10; margin-top: 0; margin-bottom: 5"><font face="Segoe UI">Name: <font color="#DA251D"><?php echo "$name";?>
</font></font></p></td></tr></table><br>
</body>
</html>

any suggestion please, thanks in advance....

Do you have to design your own templating system ? Otherwise, have a look at Smarty. It will cover all your templating needs.

If you need to create your own, then you would have to define a begin and end marker in your template, and program the parser to copy everything in between and replace your row values. (like XTemplate handles it)

yes i want to create my own template but i don't know how it can be done, please if you can quote me an example...however thank you very much for idea....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.