代码拉取完成,页面将自动刷新
<?php
include_once "conn.php";
include ("functions.php");
$apagenum = 3;//一页几个
if (isset($_GET['kind'])) {
$kind = (int)$_GET['kind'];
$page = (int)$_GET['page'];
} else {
$page = 2;
$kind = 0;
}
//$kind=$kind-1;
header("Content-type:application/json");
header('Access-Control-Allow-Origin:*');
//0.图片链接 1.日 2.月 3.标题 4.内容 5.跳转链接
$selstr="picnameinfile,teachername,nowpeople,numpeople,coursename,introducetext,c.introduceid,courseid";
if(isset($_COOKIE['majorid']) && isset($_COOKIE['enteryear']) )
{
//用户已登录 ,进行 专业限制 的分类搜索
$majorid=$_COOKIE['majorid'];
$enteryear=$_COOKIE['enteryear'];
$grade=gettoyear()-$enteryear+1;
if($kind==0)
{
//搜索全部分类
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid
and c.courseid in (select courseid
from electivelimit
where (majorid='$majorid' or majorid='0') and (grade='$grade' or grade='0')
)"
);
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid
and c.courseid in (select courseid
from electivelimit
where (majorid='$majorid' or majorid='0') and (grade='$grade' or grade='0')
)
order by courseid desc limit $index,$apagenum";
}else if($kind=="-1")
{
$searchstr=$_GET['searchstr'];
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and c.coursename like '%$searchstr%'");
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and c.coursename like '%$searchstr%'
order by courseid desc limit $index,$apagenum";
}else{
//搜索指定分类
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and kind='$kind'
and c.courseid in (select courseid
from electivelimit
where (majorid='$majorid' or majorid='0') and (grade='$grade' or grade='0')
)");
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and kind='$kind'
and c.courseid in (select courseid
from electivelimit
where (majorid='$majorid' or majorid='0') and (grade='$grade' or grade='0')
)
order by courseid desc limit $index,$apagenum";
}
}else{
//用户未登录 , 进行 无专业限制 的分类搜索
if($kind==0)
{
//搜索全部分类
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid");
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid
order by courseid desc limit $index,$apagenum";
}else if($kind=="-1")
{
$searchstr=$_GET['searchstr'];
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and c.coursename like '%$searchstr%'");
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and c.coursename like '%$searchstr%'
order by courseid desc limit $index,$apagenum";
}else{
//搜索指定分类
$result = $link->query("SELECT COUNT(*)
FROM course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and kind='$kind'");
list($row_num) = $result->fetch_row(); /// $row_num即为记录数
$index=($page-1)*$apagenum;
$sql="select $selstr
from course as c,introduce as i,teacher as t
where c.delete='0' and c.introduceid=i.introduceid and t.teacherid=c.teacherid and kind='$kind'
order by courseid desc limit $index,$apagenum";
}
}
$result = mysqli_query($link,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($link));
exit();
}else {
$results=array();
$i=0;
while ($row = mysqli_fetch_assoc($result)) {
//$selstr="picnameinfile,teachername,nowpeople,numpeople,coursename,introducetext,introduceid,courseid"
$results[$i][0]=$row['picnameinfile'];
$results[$i][1]=$row['teachername'];
$results[$i][2]=$row['nowpeople']."/".$row['numpeople'];
$results[$i][3]=$row['coursename'];
$results[$i][4]=Trim_tit($row['introducetext'],34);
$results[$i][5]=$row['introduceid'];
$results[$i][6]=$row['courseid'];
$i++;
}
}
if(count($results)==0)
{
//没有了
$results="null";
}
echo json_encode($results);
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。