Thread: Templates

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    51
    Rep Power
    15
    Hi Gurus !!!

    Please, look and run this codes:


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    # 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>

    [/code]


    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

  2. #2
  3. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    First thing that comes to mind is that the <% is typically associated with ASP, and PHP can be configured to interpret that instead of or the same as <?php or <?

    So.. I could be way wrong, but maybe that's the problem.

    You may get away with using <%% instead.

    Or simple using <variable>

    or just %variable%



    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Replies: 0
    Last Post: February 10th, 2004, 05:43 PM
  2. Nested templates in Dreamweaver MX 2004
    By switcha in forum Web Design Help
    Replies: 2
    Last Post: January 30th, 2004, 09:35 AM
  3. a good templates system ?
    By amrgo in forum PHP Development
    Replies: 3
    Last Post: January 20th, 2004, 10:12 PM
  4. Starting with templates question
    By Ramiro S in forum PHP Development
    Replies: 6
    Last Post: February 5th, 2002, 04:45 PM
  5. templates, templates, templates..
    By MkJnr in forum PHP Development
    Replies: 7
    Last Post: January 20th, 2002, 10:00 AM

IMN logo majestic logo threadwatch logo seochat tools logo