code for calc element

Sorry I was not very clear.
There are 3 lists: list 1 for buying; list 2 for selling and list 3 for bak balance. I need what writing il list 3 (bank balance) for the calc element.


step 0:
User 1 (any user) has 35 ?

step 1:
User 1 (any user) buys food for a price of 5 ? so he has 30 ?

step 2:
User 1 (any user) sell cheese for a price of 15 ? so he has 45 ?

step 3
User 1 (any user) buys tomato for a price of 5 ? so its bank balance decreases to 40 ?


Please let me know if this time the explanation is ok
 
So is your explanation a confirmation of what I've said?

Every list needs an element storing the userid and the calc element has to fetch the sums from every user in buy and sell table, e.g.
$uid ='{table3___userid}';
$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query
->select('sum(price)')
->from('table1')
->where('userid = ' . $db->quote($uid));

$db->setQuery($query);
$sumbuy = $db->loadResult();

$query = $db->getQuery(true);
$query
->select('sum(price)')
->from('table2')
->where('userid = ' . $db->quote($uid));

$db->setQuery($query);
$sumsell = $db->loadResult();

$balance = 35 -$sumbuy+$sumsell;
return $balance;
calc on save only =no

So list3 will show all users balances.
http://fabrikar.com/forums/index.php?wiki/common-php-tasks/
 
- - I have created table 1, table 2 and table 3
- - Table1 includes elements: user and price (field ? Format number:yes)
- - Table2 includes elements: user and price (field ? Format number:yes)
- - Table3 includes elements: user and sum (calc element where I have pasted the code you wrote)
- - Menu: table1 as form; table2 as form; table3 as list

I added some records into table1 form and table2 form.
Table3 list shows there are no records.
Is it correct?
I would want that table3 list shows in each moment the balance.
 
The procedure described in my last post of this thread doesn't work. Please can you find where I am wronging?
 
At least you have to add a record for every user in table3 so the calc element in those records can show anything.
 
Table 3 contains only sum field and user field. If users submit the form, they should submit a blank form because both the user field and the sum field should not be modified.
Is there a way to modify automatically (in this example the trigger should be the filling of tabl1 and table 2 forms) a list without submitting the correspondent form?
 
As I understand the user won't touch table3.
You have to create one record for every user manually (or doing it with php-plugings on form1 + 2, checking if a record of the current user is existing in table3 and adding it, if it is missing)
 
The user will see the table 3 list, but he won't be able to touch the correspondent form.
Tomorrow I will do this attempt manually. If it works, then I wll have to learn what writing in php plugin.
Thank you very much for your help.
 
I am showing what I did and what I got:

-logged as user1 and filled the form table1 by adding 20 into the Price field. List table 1 shows correctly what I have added in table1 form.
Filled table2 form by adding 10 into Price field. List table 2 shows correctly 10.
- Submitted form table3 showing Price 35 and user1 element.
- List table 3 shows 35.

I am attaching the file including the code pasted into the sum element in table 3 in order to answer Rob's question
 

Attachments

  • copied and pasted code.pdf
    17.3 KB · Views: 594
You are going to have to catch me on live chat, and show me what you are trying to do. This thread has just gotten too confusing, I need you to show me the code, the tables, the elements, and talk me through exactly what you are trying to do while I look at your server.

-- hugh
 
I am attacvhing the new structure:

Data
Form name (elements names):
Sell a lesson (category subject, subject, euro, yen, dollars)
Buy a lesson (user element, category subject, subject, euro, yen, dollars)
Buy books (category subject, subject, euro, yen, dollars)
Sell books (category subject, subject, euro, yen, dollars)
List name (elements names):
Personal home page (total euro, total yen, total dollars)

Operations
Students and teachers who buy a lesson can pay a price in euro (and/or) in yen (and/or) in dollars. The total euro (total yen and total dollars) element increases when users use sell a lesson or sell books forms and decreases when they add data in buy a lesson and buy books forms. If the amount in total euro (or in total yen or in total dollars) is smaller than the amount in euro element (or yen or dollars elements) of buy a lesson or buy books lists. When that (the total euro for example is smaller than the buying price in euro) happens, then a message appears.
 
Just to update this one ... we spent about an hour and a half on live chat discussing the overall data structures and workflow for this project. We need to have another session to work out the finer grain details.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top