Page 1 of 1
Need help please ,Simple html.tpl template
Posted: Fri Sep 19, 2008 3:40 pm
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
Re: Need help please ,Simple html.tpl template
Posted: Fri Sep 19, 2008 5:17 pm
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
Re: Need help please ,Simple html.tpl template
Posted: Sat Sep 20, 2008 9:05 am
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
Re: Need help please ,Simple html.tpl template
Posted: Sat Sep 20, 2008 9:08 am
by josh
what do you need help with
Re: Need help please ,Simple html.tpl template
Posted: Sat Sep 20, 2008 1:28 pm
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
Re: Need help please ,Simple html.tpl template
Posted: Sat Sep 20, 2008 1:50 pm
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?
Re: Need help please ,Simple html.tpl template
Posted: Sun Sep 21, 2008 11:42 am
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
Re: Need help please ,Simple html.tpl template
Posted: Sat Sep 27, 2008 7:12 am
by amera
Thank you for your help