Reputation: 3285
I have the following dilema. I only want one session to be a run at a time, for look at the following query:
$get_crs_mysqli .= (!empty($_SESSION['userSearch']))?(" AND (course_title like '%".$_SESSION['userSearch']."%') OR (course_title like '%" . $_SESSION['userCategory'] . "%') ") : '';
and
//getting the providers
function getProviders(){
if(isset($_GET['user_query']))
{
$search_query = $_GET['user_query'];
global $con;
$get_providers = "select DISTINCT course_provider from courses where (course_title like '%$search_query%' ) AND course_date1 >= CURRENT_DATE() LIMIT 5";
$run_providers = mysqli_query($con, $get_providers);
while ($row_providers=mysqli_fetch_array($run_providers)){
$provider_title = $row_providers['course_provider'];
$numberIncrease = 0;
echo '<a href="" id="liSpacing"><label id="labelSearch"><input class="filter" name="provider' . ++$numberIncrease . '" type="checkbox" value="' . $provider_title . '"> ' . $provider_title . '</label></a> <br />';
}
}
else if(isset( $_GET['crs_category']))
{
$search_query2 = $_GET['crs_category'];
global $con;
$get_providers = "select DISTINCT course_provider from courses where (course_title like '%$search_query2%' ) AND course_date1 >= CURRENT_DATE() LIMIT 5";
$run_providers = mysqli_query($con, $get_providers);
while ($row_providers=mysqli_fetch_array($run_providers)){
$provider_title = $row_providers['course_provider'];
$numberIncrease = 0;
}
}
}
Below is the page that identifies the session variables:
<?php
if(isset($_GET['user_query']))
{
$search_query = $_GET['user_query'];
$_SESSION['userSearch'] = $search_query;
$paginationresults = mysqli_query($con,"SELECT COUNT(*) FROM courses where course_title like '%$search_query%' AND course_date1 >= CURRENT_DATE() ORDER BY course_date1 ASC");
$get_total_rows = mysqli_fetch_array($paginationresults); //total records
$item_per_page = 10;
//break total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page);
}
if(isset($_GET['crs_category']))
{
$search_query_category = $_GET['crs_category'];
$_SESSION['userCategory'] = $search_query_category;
$paginationresults = mysqli_query($con,"SELECT COUNT(*) FROM courses where course_title like '%$search_query_category%' AND course_date1 >= CURRENT_DATE() ORDER BY course_date1 ASC");
$get_total_rows = mysqli_fetch_array($paginationresults); //total records
$item_per_page = 10;
//break total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page);
}
?>
The problem is that I can't have two session running at the same time, as i get an error and need to work out so that it only grabs the session being used. For instance, if the user search for a category it will come out as searchPage.php?crs_category and if they search for a particular item it will come accross as searchPage.php?user_query=html, the problem is that because the previous session is still active it conflicts with the search result.
I hope I was clear, and for any clarification, let me know.
Upvotes: -1
Views: 46
Reputation: 1357
You need to clear the previous session array value when assigning the other session value.
$_SESSION['userSearch'] = $search_query;
unset($_SESSION['userCategory']);
and
$_SESSION['userCategory'] = $search_query_category;
unset($_SESSION['userSearch']);
Upvotes: 1