Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Total of "Row Numbers" in tpl? (Hiring/Paid)

 
Post new topic   Reply to topic    Smarty Forum Index -> Help Wanted (commercial)
View previous topic :: View next topic  
Author Message
Shroomz
Smarty n00b


Joined: 29 Dec 2018
Posts: 1

PostPosted: Sat Dec 29, 2018 3:52 pm    Post subject: Total of "Row Numbers" in tpl? (Hiring/Paid) Reply with quote

Hello, I'm using the following code to list IPs in a row incrementally; however, I can't display the total number of rows at the end.


{assign var="ip" value=1}
{foreach from=$with_stateIps item=foo}
{$ip}{assign var="ip" value=$ip+1}) {$foo['ip']}
{/foreach}


Above helps me to list IPs in a row like this

1. XXX.XXX.XXX.XXX
2. XXX.XXX.XXX.XXX
3. XXX.XXX.XXX.XXX
4. XXX.XXX.XXX.XXX
.
.
999. XXX.XXX.XXX.XXX
1000. XXX.XXX.XXX.XXX

But I can't display the total number of rows like

Total: 1000

Could someone please help me out?

There are a couple more things I will request for further development of my website. Such as adding fancy charts, geo-ip integration, separating unique and raw visitors, etc. Please contact me.

Thank you,
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1438

PostPosted: Tue Jan 01, 2019 4:53 am    Post subject: Reply with quote

Code:
{foreach $var as $value}
{if $value@first}{$i=0}{/if}
{$i++}



{if $value@last}Total: $i{/if}
{/foreach}


Send your regards to PayPal (my nickname @freemail.ru )
Back to top
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 198
Location: West Coast

PostPosted: Fri Jan 04, 2019 1:28 am    Post subject: Reply with quote

See also:
https://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.total
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1438

PostPosted: Tue Jan 08, 2019 2:04 pm    Post subject: Reply with quote

Be aware that @total is not necessarily available. I.e. if you are looping an iterator or generator.
Back to top
View user's profile Send private message
deepvyas
Smarty n00b


Joined: 19 May 2017
Posts: 1
Location: India

PostPosted: Fri Jan 11, 2019 12:30 pm    Post subject: Re: Reply with quote

Hello,
Greetings!
I can help you further, If still looking for professional ?
Please let me know on same

Best Regards
Deep
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Help Wanted (commercial) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP