sasha199
Member
Hello everyone, I have several calc elements, a request to the database occurs in them
The queries are almost similar, only the condition in if is changed, how to make one query in the calc element and access it in subsequent calcs?
I want to optimize the page for faster loading, and it takes a very long time to make a request in each element
PHP:
$element = $_POST['month'];
$id = '{sbrh2_datebase___id}';
if ($element > 0) {
$month = "LAST_DAY('$element-01') + INTERVAL 1 DAY - INTERVAL 1 MONTH";
} else {
$month = "LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 1 MONTH";
}
$dbb = JFactory::getDbo();
$query='SELECT SUM(zp_day) FROM sbrh2_tabel_pers_log WHERE id = ANY(SELECT max(id) FROM sbrh2_tabel_pers_log WHERE familia = '.$id.' GROUP BY date) AND DATE = '.$month.' AND familia = '.$id.'';
$dbb->setQuery($query);
$datavalue = $dbb->loadResult();
$datavalues = $datavalue;
return (int)$datavalues;
The queries are almost similar, only the condition in if is changed, how to make one query in the calc element and access it in subsequent calcs?
I want to optimize the page for faster loading, and it takes a very long time to make a request in each element