gpt4 book ai didi

php - 使用 session

转载 作者:行者123 更新时间:2023-11-29 12:19:07 25 4
gpt4 key购买 nike

我有以下困境。我只想一次运行一个 session ,请查看以下查询:

$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 . '">&nbsp;' . $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;
}
}
}

下面是标识 session 变量的页面:

 <?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);

}


?>

问题是我不能同时运行两个 session ,因为我收到错误并且需要解决,以便它只获取正在使用的 session 。例如,如果用户搜索一个类别,它将显示为 searchPage.php?crs_category,如果他们搜索特定项目,它将显示为 searchPage.php?user_query=html,问题在于,因为前一个 session 是仍然有效,它与搜索结果冲突。

我希望我已经说清楚了,如有任何澄清,请告诉我。

最佳答案

分配另一个 session 值时,需要清除之前的 session 数组值。

$_SESSION['userSearch'] = $search_query;

unset($_SESSION['userCategory']);

$_SESSION['userCategory'] = $search_query_category;

取消设置($_SESSION['userSearch']);

关于php - 使用 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com