Get Value another table

er1dgreat

New Member
Hi... Anyone can help me.. I'm stuck . I have 2 table list.

1. Allocation
2. Overtime

In overtime have datajoin userid from allocation list

How I want get sum value 'total_hours' that's mean total is 11 for 'use' in Allocation list by userid


6f5ca451a50631fcd6812a6d695f71a2.jpg
922b233b536ff301585de901ead84b49.jpg


Sent from my RMX2195 using Tapatalk
 
Hi er1dgreat,
first of all: your question should have been the first post in the 'Community Help' section :)

Regarding your question my solution would be: the Use field should be of type 'calc' and I would do there a database query. Something like 'Select Sum(total_hours) From OvertimeStaff Where userid=employee'
This is just a rough approach and to show you the direction. For details, how to perform this task, I would propose to have a look into the wiki
 
Tq for reply... I'm try do like this

$mydb = JFactory::getDbo();
$query = $mydb->getQuery(true);
$query
->select('SUM(total_hours)')
->from($mydb->quoteName('er1dgreat_overtime_staff'))
->where($mydb->quoteName('userid').' = "{er1dgreat_allocation___employee_raw}"');
$mydb->setQuery($query);
$sum_total = $mydb->loadResult();
return $sum_total;


But get error.. pls help me..

Sent from my RMX2195 using Tapatalk
 
I'm not really a coding specialist and just try until it is working..
But what I have learned is, that the JFactory::getDbo(); is depreciated (even if it still works)

I tried to change your code a bit to the way I'm doing similiar tasks. For sure there is no guarantee it works and it would be great, if someone else comments on this


$employee='{er1dgreat_allocation___employee_raw}';
$mydb = \\Joomla\\CMS\\Factory::getContainer()->get('DatabaseDriver');
$query = $mydb->getQuery(true);
$query->select('SUM(total_hours)');
$query->from('er1dgreat_overtime_staff');
$query->where('userid =' . $employee);
$mydb->setQuery($query);
$sum_total = $mydb->loadResult();
return $sum_total;
 
Oha, again in the wrong forum. Your initial question was in the fabrik4 -> bugs, issues, suggestions section. That's why I thought you have fabrik4, have not a real issue, just a 'how to' question and I proposed to move it to the community help section. I didn't think so far as @troester did :-(

Your question should have been placed in the fabrik3 community section of the forum.

In regards of your problem you should try following code:

$employee='{er1dgreat_allocation___employee_raw}';
$mydb = JFactory::getDbo();
$query = $mydb->getQuery(true);
$query->select('SUM(total_hours)');
$query->from('er1dgreat_overtime_staff');
$query->where('userid =' . $employee);
$mydb->setQuery($query);
$sum_total = $mydb->loadResult();
return $sum_total;
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top