Re: [SMARTY] Re: Follow up on smarty problem...(More detail)

From: Date: Fri, 03 Jan 2003 21:46:25 +0000
Subject: Re: [SMARTY] Re: Follow up on smarty problem...(More detail)
References: 1 2 3 4 5  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7008@lists.php.net to get a copy of this message
On Fri, Jan 03, 2003 at 01:24:38PM -0800, Vladimir Kravtsov wrote: > No, the problem is that when I run view.php, I only see the template, but > not the values that are supposed to be in it. (I'm sorry for not explaining > myself better) > But, when I use assign instead of append, I can see only the first result of > the mysql query in a template form. (This shows that the query is fine. If I > change ASC to DESC in my MySQL query, I get a different row back) > > I do not understand why append doesn't work. This is starting to drive me > crazy :) > Thank you in advance for your help. > > PS. I couldn't get debugging to work. I set the debug tpl variable to a > folder with debug.tpl and turned on debugging, but it did not work. > PPS. When you corrected my Index.tpl you used things like {$post.subject} > even though I used {$newsbox.subject} was this deliberate, or a mistake? (Am > I supposed to do this?) > > ----- Original Message ----- > From: "M Mohr" <messju@lammfellpuschen.de> > To: "Vladimir Kravtsov" <vkravtsov@rogers.com> > Cc: "M Mohr" <messju@lammfellpuschen.de>; <smarty-general@lists.php.net> > Sent: Friday, January 03, 2003 1:07 PM > Subject: Re: Follow up on smarty problem...(More detail) > > > > On Fri, Jan 03, 2003 at 12:35:36PM -0800, Vladimir Kravtsov wrote: > > > 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> > > You have the arguments to 'foreach' wrong (you need 'from' where you have 'name'), and it looks like you maybe didn't close your {foreach} loop? Try putting error_reporting(E_ALL); at the top of the php script to increase the error reporting. Since $row is already returning an associative array, you should be able to do something simpler like this: // sql, etc., then... while ($row = mysql_fetch_array($query)) $newsbox[] = $row; $smarty->assign('newsbox', $newsbox); $smarty->display('index.tpl'); then in your template, something like this: {foreach item="news" from=$newsbox} <table> <tr><td>{$news.subject}</td><td>{$news.date}</td></tr> <!-- etc. --> </table> {/foreach} - Rob -- Rob Ellis <rob@web.ca> System Administrator, Web Networks

« previous php.smarty.general (#7008) next »