我有以下困境。我只希望一次运行一个会话,以查看以下查询:
$get_crs_mysqli .= (!empty($_SESSION['userSearch']))?(" AND (course_title like '%".$_SESSION['userSearch']."%') OR (course_title like '%" . $_SESSION['userCategory'] . "%') ") : '';
和
//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;
}
}
}
以下是标识会话变量的页面:
<?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);
}
?>
问题在于我无法同时运行两个会话,因为我收到错误并需要解决这个问题,以便只抓取正在使用的会话。例如,如果用户搜索某个类别,它将显示为searchPage.php?crs_category,如果他们搜索某个特定项目,它将作为searchPage.php?user_query = html出现,问题是因为前一个会话是仍然活跃,它与搜索结果冲突。
我希望我很清楚,如有任何澄清,请告诉我。
答案 0 :(得分:1)
在分配其他会话值时,您需要清除以前的会话数组值。
$_SESSION['userSearch'] = $search_query;
unset($_SESSION['userCategory']);
和
$_SESSION['userCategory'] = $search_query_category;
unset($_SESSION['userSearch']);