calculations

Vadim

Member
1. I have records in a list 1 with numbers, and I need to get a sum of its one column and show it in a cell of list 2. How to do it?
 
With a calc element.

Your PHP would be something like:

PHP:
$my_db = FabrikWorker::getDbo();
$my_query = $my_db->getQuery(true);
$my_query->select('SUM(your_column) AS my_total')->from('your_table');
$my_db->setQuery($my_query);
return $my_db->loadResult();

Replace 'your_column' and 'your_table' with the column name and table name you want to sum.

You will need to set "Calc on save only" to No in the calc element settings.

NOTE - this assumes your_table is on the default Fabrik database site connection. if it isn't, let me know and I'll give you the code you need to pick up the correct database object (DBO).

-- hugh
 
Thank you
this assumes your_table is on the default Fabrik database site connection.
-- hugh

How to know is it on the default Fabrik database site connection or not?

2. Now more complicated task. the same as previous, but it should summarize every record of column A, for which data in column B is equal 4.
3. And last one - it should summarize every record of column A of table 1, for which data in column B of table 1 is equal data in column C of table 2.
thank you in advance
 
How to know is it on the default Fabrik database site connection or not?
From your question I conclude that you have no additional fabrik connection, so this is the default one.

Prefilters:
You can do anything you want with prefilters type=query (defining a SQL query) or eval (defining a return value with PHP).
Usually you will set

Element:id
Condition: IN
Value: SELECT id from "here comes MySQL"
Type: query

or
Element:id
Condition: IN
Value: php code returning a list of IDs
Type: eval

This is not Fabrik but PHP and MySQL knowledge
 
This is not Fabrik but PHP and MySQL knowledge

I use Fabrik because I have not knowledge in PHP and MySQL. I asked about Fabrik element and how to use it. I guess that cheesegrits understand it, when answered at my previous question. Unlike him you use different approach, which made your answer totally useless for me. Thank you for your time and efforts, but please change your approach and give answers which can be useful for people without knowledge of PHP and MySQL or don't respond for my question - it will be just wasting time of each other.

So, my question is still open, here it is:

2. Now more complicated task. the same as previous, but it should summarize every record of column A, for which data in column B is equal 4.
3. And last one - it should summarize every record of column A of table 1, for which data in column B of table 1 is equal data in column C of table 2.
thank you in advance
 
Sorry, I got a bit confused with your different threads pointing to similar issues; the prefilter part was for your prefilter thread.

But I will follow your advice and waste my totally voluntary time giving totally useless answers in other threads.
 
Sorry, I got a bit confused with your different threads pointing to similar issues; the prefilter part was for your prefilter thread.

But I will follow your advice and waste my totally voluntary time giving totally useless answers in other threads.

Similar does not mean the same. Troester, sorry if I was too rude, you do important support here, and this is fact. You provide your support here for rather long time, and I'll take courage to assume that volunteers work is not smth frozen, it can evolve. It will be great to be more sensitive when comments more or less useful to concrete situation and level of users. Possibly it will prevent frustration and other negative things. As for me I'll try to be more restrained.

Well, and I still need an answer to my question from 12.08.2012:
2. Now more complicated task. the same as previous, but it should summarize every record of column A, for which data in column B is equal 4.
3. And last one - it should summarize every record of column A of table 1, for which data in column B of table 1 is equal data in column C of table 2.
thank you in advance
 
First, did you try out my last suggestion, and did it work?

It would also make it easier for both of us if you could give me real table and column names, so I can give you the exact code, rather than you having to edit what I give you with the actual names, which introduces the possibility of transcription errors. Kind of like translating something from one language, to another language, then back in to the first language. Much easier if we both speak the same "language".

-- hugh
 
huh, I'm afraid you didn't understand how close you was to the trouble when said about example with the same language) I have all lists, elements etc in this project in Russian, are you sure that you want to see original names instead of more convinient version for you with native A,B,C?))
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top