Page 1 of 1

[Solved] Filter out results from Formbrowser

Posted: Sat Oct 09, 2010 8:35 am
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

Re: Filter out results from Formbrowser

Posted: Sat Oct 09, 2010 8:42 am
by Millvi
I noticed that I should have put this post in Mods/Addons.
Maybe someone can move it?

Melker

Re: Filter out results from Formbrowser

Posted: Mon Oct 11, 2010 11:56 am
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

Re: Filter out results from Formbrowser

Posted: Wed Oct 13, 2010 5:54 pm
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}

Re: Filter out results from Formbrowser

Posted: Thu Oct 14, 2010 7:02 am
by Millvi
Thanks for the help!
Worked like a charm!