bea
Active Member
Hi,
I've tried to optimize a calculation with data from different databases, but without success.
The calculation works correct, but I want to get scrap2 and ist_bags with one query to calculate $total at the end. With array and loadObjectList doesn't work.
Would be great to get a hint for this.
Cheers,
Bianka
Test with loadObjectList:
Result:
I've tried to optimize a calculation with data from different databases, but without success.
The calculation works correct, but I want to get scrap2 and ist_bags with one query to calculate $total at the end. With array and loadObjectList doesn't work.
Would be great to get a hint for this.
Cheers,
Bianka
PHP:
$date ='{fab_cp4_line_tour___date_raw}';
$myDb = FabrikWorker::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
->select('SUM(losses3_scrap1)')
->from('fab_cp1_line_tour')
->where('date= ' . $myDb->quote($date))
->where('machine= 7')
->where('status= 2')
->where('shift_records = shiftorder');
$myDb->setQuery($myQuery);
$scrap2 = $myDb->loadResult();
$myDb = FabrikWorker::getDbo(false, 2);
$myQuery = $myDb->getQuery(true);
$myQuery
->select('h24_scrap2')
->from('24h_daten')
->where('date= ' . $myDb->quote($date))
->where('machine= 7');
$myDb->setQuery($myQuery);
$scrap2 = $myDb->loadResult();
$myDb = FabrikWorker::getDbo(false, 2);
$myQuery = $myDb->getQuery(true);
$myQuery
->select('h24_ist_bags')
->from('24h_daten')
->where('date= ' . $myDb->quote($date))
->where('machine= 7');
$myDb->setQuery($myQuery);
$ist_bags = $myDb->loadResult();
$total = ((($scrap1+$scrap2)*100) /$ist_bags);
if ($total == NULL) {
return '';}
else return sprintf('%01.1f',$total).'%';
Test with loadObjectList:
PHP:
$myDb = FabrikWorker::getDbo(false, 2);
$myQuery = $myDb->getQuery(true);
$myQuery
->select(array('h24_scrap2','h24_ist_bags'))
->from('24h_daten')
->where('date= ' . $myDb->quote($date))
->where('machine= 7');
$myDb->setQuery($myQuery);
$rows = $myDb->loadObjectList();
var_dump($rows);exit;
array(1) { [0]=> object(stdClass)#4648 (2) { ["h24_scrap2"]=> string(4) "1000" ["h24_ist_bags"]=> string(5) "20000" } }
Last edited: