RE: [SMARTY] rownum with foreach?
| From: | Josh Johnson | Date: | Fri, 23 Aug 2002 15:44:01 +0000 |
| Subject: | RE: [SMARTY] rownum with foreach? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5818@lists.php.net to get a copy of this message | ||
Then use a counter?... I've used this before:
{assign var=counter value=1}
{foreach ...}
{$counter} ...
{assign var=counter value=$counter+1}
{/foreach}
-- Josh
-----Original Message-----
From: Peter Billen [mailto:peter@clueless.be]
Sent: Friday, August 23, 2002 10:59 AM
To: 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
foreach from=$news_item.comments item=comment key=comment_id}
<li>{$comment_id} . . .
Yup, I had that before, but that's not what I want.
I always want to start with 1, and not with the value comment_id that is
in the database. If a comment for example has primary key 543 in the
database, then it also says on the site 543, which is very logical.
Thanks for your input
Peter
-----Original Message-----
From: Josh Johnson [mailto:mailing_lists@allusiveimage.com]
Sent: vrijdag 23 augustus 2002 14:32
To: peter@clueless.be; 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
If you know the news_id, try {foreach
from=$newsListData.$news_id.comments item=comment key=comment_id}
That should set $comment to the current comment (so
$comment.comment_text would contain comment text), and $comment_id to
the key of the array.
If you don't know the news_id, loop over the $newsListData array, then
for each news_id, loop through the comments:
{foreach from=$newsListData item=news_item key=news_id}
News Info:<br>
Id {$news_id}<br>
Topic: {$news_item.news_topic}<br>
...
Comments:
{foreach from=$news_item.comments item=comment key=comment_id}
<li>{$comment_id}. $comment.text
{/foreach}
{/foreach}
I haven't tested it, but that's the logic that comes to mind when I look
at the way your array is set up. Most of the recursive looping I've done
used objects, so my assoc array syntax might be messed up (critique,
anyone?), but that's the basic idea the way I see it.
Hope that helps :)
-- Josh
-----Original Message-----
From: Peter Billen [mailto:peter@clueless.be]
Sent: Friday, August 23, 2002 6:19 AM
To: 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
array $newsListData:
-> ['news_id'] (x)
-> ['news_topic']
-> ...
-> ['comments'] (x)
-> ['comment_id'] (x)
-> ['comment_text']
-> ...
Not good?
Thanks,
Peter
-----Original Message-----
From: Josh Johnson [mailto:mailing_lists@allusiveimage.com]
Sent: donderdag 22 augustus 2002 21:49
To: peter@clueless.be
Subject: RE: [SMARTY] rownum with foreach?
How is your array structured?
-- Josh
-----Original Message-----
From: Peter Billen [mailto:peter@clueless.be]
Sent: Thursday, August 22, 2002 2:21 PM
To: 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
Nope, I already tried that, didn't work.
Thanks for your input.
Peter
-----Original Message-----
From: Josh Johnson [mailto:mailing_lists@allusiveimage.com]
Sent: donderdag 22 augustus 2002 19:28
To: peter@clueless.be; 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
Try changing {$smarty.foreach.comments.rownum} to {$comment_id.rownum}
-- Josh
-----Original Message-----
From: Peter Billen [mailto:peter@clueless.be]
Sent: Thursday, August 22, 2002 11:10 AM
To: 'Smarty General'
Subject: RE: [SMARTY] rownum with foreach?
Little fuckup, sorry (read again below)
Peter
-----Original Message-----
From: Peter Billen [mailto:peter@clueless.be]
Sent: donderdag 22 augustus 2002 17:09
To: 'Smarty General'
Subject: [SMARTY] rownum with foreach?
Hi,
Why doesnt this work?
{foreach from=$newsListData.comments item=comment_id name=comments}
. . .
Comment #{$smarty.foreach.comments.rownum}
. . .
{/foreach}
Thanks,
Peter
--
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
--
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
--
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