我想要做的是以下内容。 在URL中,一次只能出现一个变量:
$search_query = $_GET['user_query'];
$search_query2 = $_GET['crs_category'];
所以我想做的是以下几点。
如果user_query是url中存在的那个,则执行以下行
$get_cats = "select * from courses where (course_title like '%$search_query%' ) AND course_date1 >= CURRENT_DATE()";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$crs_sub1 = $row_cats['course_subc1'];
$crs_sub2 = $row_cats['course_subc2'];
$crs_sub3 = $row_cats['course_subc3'];
$crs_sub4 = $row_cats['course_subc4'];
$crs_sub5 = $row_cats['course_subc5'];
echo "<a href='searchPage.php?cat=$crs_sub1' id='liSpacing'><label id='labelSearch'><input type='checkbox' name='checkbox' value='value'> $crs_sub1</label></a> <br />";
}
但是,如果它的url中存在crs_category变量,则执行以下操作:
$get_cats = "select * from category where (category_title like '%$search_query2%' ) AND course_date1 >= CURRENT_DATE()";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$crs_sub1 = $row_cats['course_subc1'];
$crs_sub2 = $row_cats['course_subc2'];
$crs_sub3 = $row_cats['course_subc3'];
$crs_sub4 = $row_cats['course_subc4'];
$crs_sub5 = $row_cats['course_subc5'];
echo "<a href='searchPage.php?cat=$crs_sub1' id='liSpacing'><label id='labelSearch'><input type='checkbox' name='checkbox' value='value'> $crs_sub1</label></a> <br />";
}
问题是如下,只有user_query或crs_category将一次显示在URL中,而不是两者都显示,因此我收到显示的错误。我想要做的是,如果该url变量等于this,请抓取这些信息,或者如果此url变量等于那个抓住那些items.w
另一方面,我还想做以下事情 任何帮助将不胜感激
答案 0 :(得分:0)
我相信这就是你想要的......
<?php
if(isset($_GET['user_query']))
{
$search_query = $_GET['user_query'];
$get_cats = "select * from courses where (course_title like '%$search_query%' ) AND course_date1 >= CURRENT_DATE()";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$crs_sub1 = $row_cats['course_subc1'];
$crs_sub2 = $row_cats['course_subc2'];
$crs_sub3 = $row_cats['course_subc3'];
$crs_sub4 = $row_cats['course_subc4'];
$crs_sub5 = $row_cats['course_subc5'];
echo "<a href='searchPage.php?cat=$crs_sub1' id='liSpacing'><label id='labelSearch'><input type='checkbox' name='checkbox' value='value'> $crs_sub1</label></a> <br />";
}
}
else if(isset($_GET['crs_category']))
{
$search_query2 = $_GET['crs_category'];
$get_cats = "select * from category where (category_title like '%$search_query2%' ) AND course_date1 >= CURRENT_DATE()";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$crs_sub1 = $row_cats['course_subc1'];
$crs_sub2 = $row_cats['course_subc2'];
$crs_sub3 = $row_cats['course_subc3'];
$crs_sub4 = $row_cats['course_subc4'];
$crs_sub5 = $row_cats['course_subc5'];
echo "<a href='searchPage.php?cat=$crs_sub1' id='liSpacing'><label id='labelSearch'><input type='checkbox' name='checkbox' value='value'> $crs_sub1</label></a> <br />";
}
}
?>