Re: [SMARTY] Take a look at this problem
| From: | M Mohr | Date: | Fri, 03 Jan 2003 09:19:24 +0000 |
| Subject: | Re: [SMARTY] Take a look at this problem | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6997@lists.php.net to get a copy of this message | ||
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?