Re: Follow up on smarty problem...(More detail)
| From: | Vladimir Kravtsov | Date: | Fri, 03 Jan 2003 21:24:38 +0000 |
| Subject: | Re: Follow up on smarty problem...(More detail) | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7007@lists.php.net to get a copy of this message | ||
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>
>
> hmm, i guess:
>
> {foreach from=newsbox item=post} {* one table for each post in newsbox *}
> <table width="75%" height="73" border="1"
> cellpadding="2" cellspacing="0"
bordercolor="#000000">
> <tr>
> <td width="75%"
> height="23"><strong>{$post.subject}</strong></td>
> <td width="25%"><div align="right">{$post.date}
> {$post.time}</div></td>
> </tr>
> <tr>
> <td height="21" colspan="2" align="left"
> valign="top">{$post.body}</td>
> </tr>
> <tr>
> <td colspan="2" align="left" valign="top"><div
> align="right">By: <a
>
> href="mailto:{$post.authoremail}">{$post.authorname}</a></div></td>
> </tr>
> </table>
> {/foreach} {* end of foreach block *}
>
>
> newsbox is your array which is an array of hash-arrays.
>
> the foreach-loop assigns in each iteration one element of newsbox to
> post, which becomes a hash-array.
>
> > 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.
>
> if you mean by "blank page", that the sourcecode of the page is empty,
> then there might be a php-error on the page. you should check your
> php's error_reporting and display_errors settigns. or your query
> returned zero posts, then of course, there are zero tables
> displayed.
>
> have a look at
> http://smarty.php.net/manual/en/chapter.debugging.console.php
> to see,
> how you can inspect what is actually assigned to your template's
> variables.
>
> HTH
> messju
>
>
> > 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
> > >
> > >