I want to update the counts if the user makes a selection in Advanced Search, but they are not updated when the search result is first displayed. They are displayed if I then refresh the page in the browser. It looks to me like $filter is set after the footer is displayed. Is this correct and how can I get round it?
In both Recordset_Selecting and Recordset_Searching I have the following:
if(!session_id()) session_start();
$_SESSION['selectFilter'] = $filter;
customtestheader.php
<?php
namespace PHPMaker2023\elsielge;
include_once __DIR__ . "/../vendor/autoload.php";
// Require files
// exclude alerts
//$userslevels = array(-2);
//if (!in_array(CurrentUserLevel(), $userslevels) && !empty($_SESSION['selectFilter'])) {
if (!empty($_SESSION['selectFilter'])) {
$count1 = 0;
$count2 = 0;
}
// Header Alerts
$newfilter = "";
if(!session_id()) session_start();
if (!empty($_SESSION['selectFilter'])) {
$newfilter = $_SESSION['selectFilter'];
$string = "`league_id`";
$replace = "A.`league_id`";
$newfilter = str_replace($string,$replace,$newfilter);
$string = "`club_id`";
$replace = "A.`club_id`";
$newfilter = str_replace($string,$replace,$newfilter);
// this is a work around to display league fixture alerts
$string = "`away_club_id`";
$replace = "A.`away_club_id`";
$newfilter = str_replace($string,$replace,$newfilter);
$string = "`competition_id`";
$replace = "A.`competition_id`";
$newfilter = str_replace($string,$replace,$newfilter);
$string = "`division_id`";
$replace = "A.`division_id`";
$newfilter = str_replace($string,$replace,$newfilter);
$string = "`opposition`";
$replace = "A.`opposition`";
$newfilter = str_replace($string,$replace,$newfilter);
$string = "`team`";
$replace = "A.`team`";
$newfilter = " WHERE " . str_replace($string,$replace,$newfilter);
}
//var_dump($newfilter);
// Teams playing more than once on same day
$sql = "SELECT Count(DISTINCT A.fixture_id) from `viewzz_team_clash` as A ". $newfilter;
$count1 = ExecuteScalar($sql);
if ($count1 > 0) {
$bg1 = 'text-red';
$fa_icon = 'fa-warning';
} else {
$count1 == 0;
$bg1 = 'text-green';
$fa_icon = 'fa-check-circle';
}
$title1 = 'Fixtures with Teams Playing Twice in a Day';
// Grounds with matches at the same time
$sql = "SELECT Count(DISTINCT A.fixture_id) from `viewzz_ground_clash` as A ". $newfilter;
$count2 = ExecuteScalar($sql);
if ($count2 > 0) {
$bg2 = 'text-yellow';
$fa_icon2 = 'fa-warning';
} else {
$count2 == 0;
$bg2 = 'text-green';
$fa_icon2 = 'fa-check-circle';
}
$title2 = 'Matches on Grounds at the Same Time';
//
$row1 = array('bg'=>$bg1,'number'=>$count1,'title'=>$title1,'icon'=>$fa_icon,'link'=>'ViewzzTeamClashList');
$row2 = array('bg'=>$bg2,'number'=>$count2,'title'=>$title2,'icon'=>$fa_icon2,'link'=>'ViewzzGroundClashList');
$merge = array_merge(array($row1),array($row2));
//$merge = array_merge($merge,array($row3));
Display_Alerts($merge);
?>
function Display_Alerts($row_data) {
// exclude alerts
$userslevels = array();
if (!in_array(CurrentUserLevel(), $userslevels)) {
$sum = 0;
foreach ($row_data as $item) {
$sum += $item['number'];
}
$footer =" <li class='nav-item dropdown'>
<a class='nav-link' data-bs-toggle='dropdown' href='#' >
<i class='fas fa-bell'></i>";
if ($sum > 0 ) {
$footer .="<span class='badge bg-warning navbar-badge'>" . $sum ."</span>";
} else {
$footer .="<span class='badge bg-success navbar-badge'>" . $sum ."</span>";
}
$footer .="</a>
<div class='dropdown-menu dropdown-menu-lg dropdown-menu-end'>
<span class='dropdown-item dropdown-header'>" . $sum ." Notifications</span>
<div class='dropdown-divider'></div>
";
// var_dump($row_data);
$count=0;
foreach ($row_data as $row) {
// var_dump($row);
$footer .=" <a href='". $row['link'] ."' class='dropdown-item' " . $row['bg']. ">
<span class='" . $row['bg'] . "'>
<i class='fas mr-2 ". $row['icon'] . "'></i></span><span> ".$row['number']. " " . $row['title'] ."</span>
</a>
<div class='dropdown-divider'></div>";
/*
if ($row['number'] <> 0) {
$footer .= "<a href='" . $row['link'] . "' class='small-box-footer'>
More info <i class='fa fa-arrow-circle-right'></i>
</a>";
} else {
$footer .= "<p class='small-box-footer'>There are none to display </p>";
}
;
$footer .= "</div>
</div>
<!-- ./col -->";
*
*/
$count++;
}
$footer .="</div>
</li>";
print_r($footer);
}
}