Follow up on smarty problem...(More detail)
| From: | Vladimir Kravtsov | Date: | Fri, 03 Jan 2003 20:35:36 +0000 |
| Subject: | Follow up on smarty problem...(More detail) | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7004@lists.php.net to get a copy of this message | ||
Hmmmmm i'm not sure if I understand correctly. This is what I did:
*/ VIEW.PHP */
<?php
require ('common.php'); //Includes all of the pre-written functions
connectdb(); //Connects to the database
//This is the Smarty template system
define('SMARTY_DIR','c:/inetpub/wwwroot/newphp/x-news/');
require(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = "c:/inetpub/wwwroot/newphp/x-news/templates/";
$smarty->compile_dir = "c:/inetpub/wwwroot/newphp/x-news/templates_c/";
$query = mysql_query("SELECT postid, subject, body, authoremail, authorname,
date, time FROM posts ORDER BY postid ASC");
while ($row = mysql_fetch_array($query)) {//Selects all of the posts
//Assign the information to the template
$smarty->append('newsbox',
Array('postid'=>$row['postid'], 'subject' =>
$row['subject'], 'body'
=>$row['body'], 'authoremail'
=>$row['authoremail'],'date' =>$row['date'],
'time' =>$row['time'], 'authorname' =>
$row['authorname'] ));
}
//Shows the page
$smarty->display('index.tpl');
?>
/* INDEX.TPL */
{foreach name=newsbox item=postid}
<table width="75%" height="73" border="1" cellpadding="2"
cellspacing="0"
bordercolor="#000000">
<tr>
<td width="75%"
height="23"><strong>{$newsbox.subject}</strong></td>
<td width="25%"><div align="right">{$newsbox.date}
{$newsbox.time}</div></td>
</tr>
<tr>
<td height="21" colspan="2" align="left"
valign="top">{$newsbox.body}</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><div
align="right">By: <a
href="mailto:{$newsbox.authoremail}">{$newsbox.authorname}</a></div></td>
</tr>
</table>
BUT, this gives me a blank page. What I want to do is go through every
database entry in "posts" and show each entry as a table like that ^. (I'm
coding a news script)
I used to use FastTemplate which did this very easily. Unfortunately,
FastTemplate no longer works with the latest version of PHP and Smarty seems
more powerful.
Thank you in advance for your help.
----- Original Message -----
From: "M Mohr" <messju@lammfellpuschen.de>
To: "Vladimir Kravtsov" <vkravtsov@rogers.com>
Cc: <smarty-general@lists.php.net>
Sent: Friday, January 03, 2003 1:19 AM
Subject: Re: [SMARTY] Take a look at this problem
> hello,
>
> On Thu, Jan 02, 2003 at 07:34:06PM -0800, Vladimir Kravtsov wrote:
> > I have the following code:
> >
> > <?php
> > require ('common.php'); //Includes all of the pre-written functions
> > connectdb(); //Connects to the database
> > //This is the Smarty template system
> > define('SMARTY_DIR','c:/inetpub/wwwroot/newphp/x-news/');
> > require(SMARTY_DIR.'Smarty.class.php');
> > $smarty = new Smarty;
> > $smarty->template_dir = "c:/inetpub/wwwroot/newphp/x-news/templates/";
> > $smarty->compile_dir = "c:/inetpub/wwwroot/newphp/x-news/templates_c/";
> >
> >
> > $query = mysql_query("SELECT postid, subject, body, authoremail,
authorname, date, time FROM posts ORDER BY postid ASC");
> > while ($row = mysql_fetch_array($query)) {//Selects all of the posts
> > //Assign the information to the template
> > $smarty->assign('newsbox',
> > Array('postid'=>$row['postid'], 'subject' =>
> > $row['subject'], 'body'
=>$row['body'], 'authoremail'
=>$row['authoremail'],'date' =>$row['date'],
'time' =>$row['time'], 'authorname' =>
$row['authorname'] ));
> >
>
> how does the template look like?
> it looks to me you want to do $smarty->append('newsbox', ...) instead
> of assign, instead of assign. assign overwrites the old value of newsbox.
>
> in your template you can loop over your newsbox array with foreach.
>
> HTH
> messju
>
> > }
> > $smarty->display('index.tpl');
> > //Shows the page
> >
> >
> >
> >
> >
> >
> >
> > ?>
> >
> > This only prints the first entry in my databse (my template just prints
things like newsbox.postid.
> > How can I make this print all of the entries?
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>