Re: [SMARTY] Sigh...I'm still having problems.
| From: | Rob Ellis | Date: | Fri, 03 Jan 2003 22:25:08 +0000 |
| Subject: | Re: [SMARTY] Sigh...I'm still having problems. | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7011@lists.php.net to get a copy of this message | ||
On Fri, Jan 03, 2003 at 01:56:38PM -0800, Vladimir Kravtsov wrote:
> View.php does not show any errors at all. (Even when I add that error
> reporting line)
It sounds like your PHP isn't reporting any errors? you can turn that
on in the php.ini or try
ini_set('display_errors', '1');
error_reporting(E_ALL);
at the top of your script ?
> When I do what you told me, view.php shows nothing (not even the template)
> I've altered my index.tpl likewise:
> {foreach item="newsbox" from=$newsbox}
You can't use the same variable name for 'item' and 'from' in the foreach.
Try '{foreach item="news" from=$newsbox}', with appropriate
changes to the rest of the template ({$news.subject}, etc.).
- Rob
> <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>
> {/foreach}
>
> And still this only works when I use assign in view.php (it only shows the
> first entry then). If I use append it just shows the empty template.
> ----- Original Message -----
> From: "Rob Ellis" <rob@web.ca>
> To: <smarty-general@lists.php.net>
> Sent: Friday, January 03, 2003 1:46 PM
> Subject: Re: [SMARTY] Re: Follow up on smarty problem...(More detail)
>
>
> > 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
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>