Hi Gurus !!!
Please, look and run this codes:
<?
# conf.php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "projeto";
mysql_connect($hostname,$username,$password) or die ("Erro: Conexão não estabelecida");
mysql_select_db("$dbname") or die ("Erro: Não foi possível acessar o banco de dados");
#HTML - TAGS
$temp = str_replace("<%ID%>", $id, $temp);
$temp = str_replace("<%Categoria%>", $categoria, $temp);
$temp = str_replace("<%Nome%>", $nome, $temp);
$temp = str_replace("<%Texto%>", $texto, $temp);
$temp = str_replace("<%Imagem%>", $imagem, $temp);
$temp = str_replace("<%Links%>", $links, $temp);
?>
************************************************************
<?
# teste.php
require("conf.php");
Function OpenTemplate($tempname) {
Global $id,$categoria,$nome,$texto,$imagem,$links;
$tempurl="c:/Apache/htdocs/admin";
$tempfile = fopen("$tempurl/$tempname", "r");
while(!feof($tempfile))
{
$temp = fgets($tempfile,255);
include("conf.php");
print($temp);
}
fclose($tempfile);
}
$result = mysql_query("select * from empresa");
function links($result) {
Global $id,$categoria,$nome,$texto,$imagem,$links;
while($row = mysql_fetch_array($result)) {
$id = $row["ID"];
$categoria = $row["Categoria"];
$nome = $row["Nome"];
$texto = $row["Texto"];
$imagem = $row["Imagem"];
OpenTemplate("links.html");
}
}
$links = links($result);
OpenTemplate("teste.html");
?>
************************************************************
<!-- links.html -->
<div align="center"><center>
<table border="0" width="100%">
<tr>
<td width="33%"></td>
<td width="33%"><p>
<b><%ID%><br><%Categoria%><br><%Nome%><br>
<%Texto%><br><%Imagem%></td></b>
<td width="34%"></td>
</tr>
</table>
</center></div>
************************************************************
<!-- teste.html -->
<div align="center"><center>
<table border="0" width="100%">
<tr>
<td width="33%"></td>
<td width="33%"><p>
<b><%Links%></b></td>
<td width="34%"></td>
</tr>
</table>
</center></div>
OK ?!?! ... I'm trying to run this, but there are something that I can't see that's wrong.
I want to use the tag <%Links%> to list all rows from my table in the teste.html template, but I receive only the last row from the table.
Any ideas to solve this ???
Regards,
marcoBR