Re: [Tiki-devel] Counting items resulting from items > item list (smarty ?)

Jonny Bradley via TikiWiki-devel <[email protected]>
Newsgroups gmane.comp.cms.tiki.devel
Message-ID <[email protected]>
Aha, if you're using mysql engine then you get those token things unless you use a {FORMAT} pluglette, and then you'd probably get the same as the _text field.

Ok, the next strategy might be to count the comma characters in tracker_field_productsboughtChildName_text (and then add one)

No time for a full example now, but maybe preg_match('/,/', $row. tracker_field_productsboughtChildName_text) might return the number of commas?

HTH

jonny



> On 15 Mar 2021, at 16:42, Bsfez Tiki <[email protected]> wrote:
> 
> Thanks Jonny,
> 
> 
> I kept my list plugin as is (was working with the templates/search/list/count template) and create a smarty template with the code you posted.
> 
> phpStorm doesn’t like the ":count" and I have a syntax error.
> 
> <Screen Shot 2021-03-15 at 13.00.53 .png>
> 
> But I searched the internet and found this: https://stackoverflow.com/questions/12960598/get-value-count-in-an-array-with-smarty
> 
> I adapted the code to this:
> 
> {$childNameCount = 0}
> {foreach $results as $row}
>    {assign var=childNameCount value = $childNameCount + count($row.tracker_field_productsboughtChildName)}
> {/foreach}
> {$childNameCount}
> 
> But this is outputting the items count (13) not the names count (15)
> 
> Then I recheck each field and find out that on Tiki22 the output of a item link field is a… token.
> Here the value I have for an item with 3 kids:
> tracker_field_productsboughtChildName => "tokenyvvbvdfbvbzxpyccpzvttbearppucfqz..."
> tracker_field_productsboughtChildName_text => "גפן, מרום"
> 
> I tried
> {$childNameCount = 0}
> {foreach $results as $row}
>    {assign var=childNameCount value = $childNameCount + count($row.tracker_field_productsboughtChildName_text)}
> {/foreach}
> {$childNameCount}
> 
> But then the output is 0
> 
> Darn…
> 
> B
> 
> PS: On this specific I don’t have doublons, but yes... yes I have doublons, 2 kids with the same name 😂😂😂
> 
>> On 15 Mar 2021, at 12:25 , Jonny Bradley via TikiWiki-devel <[email protected]> wrote:
>> 
>> Hi Bernard
>> 
>> You can use the php count() function http://www.php.net/manual/en/function.count.php in smarty, which you can use as either a function or modifier, and tracker_field_productsboughtChildName i think should be an array, right?
>> 
>> So then it depends if you need unique names, or a total including duplicates (your example doesn't have duplicates, so let's go with total, as that's simpler ;)
>> 
>> 
>>  {$childNameCount = 0}
>> 
>>  {foreach $results as $row}
>>    {$childNameCount = $childNameCount + $row.tracker_field_productsboughtChildName:count}
>>  {/foreach}
>> 
>> Totally unchecked and untested, but something like that should work :)
>> 
>> jonny
>> 
>> 
>> 
>>> On 15 Mar 2021, at 06:40, Bsfez Tiki via TikiWiki-devel <[email protected]> wrote:
>>> 
>>> Hello,
>>> 
>>> (back to business ;-) )
>>> 
>>> With the plugin List and the unified index we have a "$count" variable.
>>> This variable will display the number of results.
>>> 
>>> But how can I count the number of items from an item list field within its array ?
>>> 
>>> This is the tiki-pluginlist_experiment.php output for one kid (this is an item list field):
>>> tracker_field_productsboughtChildName_text => "אגם"
>>> For 2 kids:
>>> tracker_field_productsboughtChildName_text => "אוריין שחר, ליאור"
>>> 
>>> IE: I have items with an item list.
>>> Item1 name(s): Jonny, Torsteen
>>> Item2 name(s): Marc
>>> Item3 name(s) : Bernard, Gary
>>> Item4 name(s) : Jyhem
>>> 
>>> I need a people count (6)
>>> 
>>> Any ideas on how to do that ?
>>> B
>>> _______________________________________________
>>> TikiWiki-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel
>> 
>> 
>> 
>> _______________________________________________
>> TikiWiki-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel
> 



_______________________________________________
TikiWiki-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.