Need help please ,Simple html.tpl template

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amera
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 6:49 am

Need help please ,Simple html.tpl template

Post by amera »

Hello
I am new to php want to learn it by examples have a tpl template simple & easy for static web site , i want to load the content to it from mysql database & need help from you because i failed to do it by my self .

This is the link to the template .
http://www.broculos.net/tutorials/how_t ... 0080315/en

This is list_records.php

Code: Select all

<?php
include "config.php";
$sql="SELECT * FROM news ";
$result=mysql_query($sql);
?>
<table width="400" border="0" align="right" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="400" border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><div align="right"><strong>???????</strong><strong></strong></div></td>
</tr>
 
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td rowspan="-1" align="center"><div align="right"><a href="update.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a></div></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
 
?>
Thank you for your kind attention
Amera
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Need help please ,Simple html.tpl template

Post by josh »

How do you fail a tutorial? start from the beginning and follow each step, if there is terminology that is confusing you and you ask a specific question there will be plenty of people willing to help
amera
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 6:49 am

Re: Need help please ,Simple html.tpl template

Post by amera »

DevNet Resident
Thank you for your kindness , i told you that i am new to php but i forget to tell you my tongue is not english , thank you for your useful help
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Need help please ,Simple html.tpl template

Post by josh »

what do you need help with
amera
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 6:49 am

Re: Need help please ,Simple html.tpl template

Post by amera »

Thank you
I try to load content from database , it gives one record when the script

Code: Select all

$sql="SELECT * FROM news ";
$result=mysql_query($sql);
 
how can i display all records as the script above.
Or display the result of

Code: Select all

$sql="SELECT * FROM news ";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td rowspan="-1" align="center"><div align="right"><a href="update.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a></div></td>
</tr>
 
 
Thank you for your kind attention
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Need help please ,Simple html.tpl template

Post by josh »

amera wrote:I try to load content from database , it gives one record when the script
When you run the SQL or your code only outputs one table row?
how can i display all records as the script above.
Your script looks like it should output allr ecords, have you checked that there is actually more then one row in the table?
Or display the result of
that code should do that already, what is your specific question or error you're experiencing?
amera
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 6:49 am

Re: Need help please ,Simple html.tpl template

Post by amera »

Dear DevNet Resident
The code into file list_records.php do it but i want to merge this file with the html template engine http://www.broculos.net/tutorials/how_t ... 0080315/en
I failed to do it , please download the template file http://www.broculos.net/files/articles/ ... Engine.rar
I want to merge list_records.php with user_profile.php.
This is the code of user_profile.php

Code: Select all

?php
 
    include("template.class.php");
    
    /**
     * Creates a new template for the user's profile.
     * Fills it with mockup data just for testing.
     */
    $profile = new Template("user_profile.tpl");
    $profile->set("username", "monk3y");
    $profile->set("photoURL", "images/photo.jpg");
    $profile->set("name", "Monkey man");
    $profile->set("age", "23");
    $profile->set("location", "Portugal");
    
    /**
     * Loads our layout template, settings its title and content.
     */
    $layout = new Template("layout.tpl");
    $layout->set("title", "User profile");
    $layout->set("content", $profile->output());
    
    /**
     * Outputs the page with the user's profile.
     */
    echo $layout->output();
    
?>
And this is the code of list_records.php

Code: Select all

<?php
include "config.php";
$sql="SELECT * FROM news ";
$result=mysql_query($sql);
?>
<table width="400" border="0" align="right" cellpadding="0" cellspacing="1">
<tr>
<td>
<table width="400" border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><div align="right"><strong>???????</strong><strong></strong></div></td>
</tr>
 
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td rowspan="-1" align="center"><div align="right"><a href="update.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a></div></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
 
?>
 
I need to know how can i put the result of this part of code from list_records.php

Code: Select all

<tr>
<td rowspan="-1" align="center"><div align="right"><a href="update.php?id=<? echo $rows['id']; ?>"><? echo $rows['title']; ?></a></div></td>
</tr>
 
Into the this part from user_profile.php

Code: Select all

$profile = new Template("user_profile.tpl");
    $profile->set("username", "[color=#FF0000]monk3y[/color]");
            [b]Please change $content->set("content", "[color=#FF0000]the result code from list_records.php[/color]");[/b]    
 
How can i do it ?
Thank you DevNet Resident
amera
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 6:49 am

Re: Need help please ,Simple html.tpl template

Post by amera »

Thank you for your help
Post Reply