Ai
4 Star 0 Fork 0

softwareengineering1/software

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Courselibserver.php 6.85 KB
一键复制 编辑 原始数据 按行查看 历史
softwareengineering1 提交于 2021-05-30 19:41 +08:00 . contents of comment
<?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);
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/softwareengineering1/software.git
git@gitee.com:softwareengineering1/software.git
softwareengineering1
software
software
master

搜索帮助