[Solved] Filter out results from Formbrowser

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Millvi
New Member
New Member
Posts: 4
Joined: Sat Oct 09, 2010 8:20 am

[Solved] Filter out results from Formbrowser

Post by Millvi »

Hi!

I need help with filtering out results from saved forms in Formbrowser.

I have tried but can´t seem to get it to work. As you probably will see I´m not used to code in PHP but I have given it a try  :)

This is what I would like to do:

1. Filter out all the saved data from a field called Units.
2. Sum up all the units where the data in field Status is Levande
3. Show the result on my webpage.

I have 2 problems with the code right now.

1. I can´t get the sum to show.
2. If I could it would show the sum as many times as the field Status contains the data Levande, and I would like to show the result just 1 time.

This is the code in my template for the actual request:

Code: Select all

{foreach from=$list item=entry}
              {foreach from=$entry->fields item=status}
                  {if $status == Levande}
			{section name=vals start=0}
				{if isset($entry->fields[$smarty.section.vals.index])}
<td>
Levande units: {units}
</td>
				{else}
<td></td>
				{/if}
                        {/section}
                   {/if}
               {/foreach}
         {/foreach}
This is the code for the UDT units:

Code: Select all

$summa = 0;

$u = $entry->fields[4];

$totalt = $summa + $u;

echo $totalt;
If someone could help med with this it would be great!
Melker
Last edited by Millvi on Thu Oct 14, 2010 7:03 am, edited 1 time in total.
Millvi
New Member
New Member
Posts: 4
Joined: Sat Oct 09, 2010 8:20 am

Re: Filter out results from Formbrowser

Post by Millvi »

I noticed that I should have put this post in Mods/Addons.
Maybe someone can move it?

Melker
Millvi
New Member
New Member
Posts: 4
Joined: Sat Oct 09, 2010 8:20 am

Re: Filter out results from Formbrowser

Post by Millvi »

Someone has got to be able to help me with this one!?
There has to be a way to add up the units in my case. I have managed to show the units on my webpage but I find it impossible to add them together.
When I use this code:

Code: Select all

{foreach from=$list item=entry}
              {foreach from=$entry->fields item=status}
                  {if $status == Levande}
			{section name=vals start=0}
				{if isset($entry->fields[$smarty.section.vals.index])}
<td>
Levande units: {$entry->fields[4]}
</td>
				{else}
<td></td>
				{/if}
                        {/section}
                   {/if}
               {/foreach}
         {/foreach}
You can se the result here http://www.ace-pro.se/index.php?page=portfolj, but as you can see the loop runs 3 times since it is 3 bets that are live (Levande).
I would of course want to show it one time like this:
Levande units: 19

One thing I noticed was wrong in the UDT is that $summa is set to 0 every loop. But it doesn´t help that I set $summa to 0 before the loop starts. I still don´t get the outcome I would like.

Please help me with this one. It would really make my day  :)
Melker
User avatar
sjg
Power Poster
Power Poster
Posts: 310
Joined: Thu Jan 27, 2005 5:11 pm

Re: Filter out results from Formbrowser

Post by sjg »

Without seeing what the data and the form look like, it's hard to know exactly what it is you're trying to do.

But it looks like you might be able to do it entirely in Smarty:

Code: Select all

{foreach from=$list item=entry}
    {foreach from=$entry->fields item=status}
        {if $status == 'Levande'}
            {assign var='sum' value='0'}
             {section name=vals start=0}
                {if isset($entry->fields[$smarty.section.vals.index])}
                    {assign var='sum' value=`$sum + $entry->fields[4]`}
                {/if}
             <td>Levande units: {$sum}</td>
             {/section}
         {/if}
     {/foreach}
  {/foreach}
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
Millvi
New Member
New Member
Posts: 4
Joined: Sat Oct 09, 2010 8:20 am

Re: Filter out results from Formbrowser

Post by Millvi »

Thanks for the help!
Worked like a charm!
Post Reply

Return to “Modules/Add-Ons”