<?php
header('content-type:text/html;charset=utf-8');
//连接数据库
$link=mysqli_connect('127.0.0.1','root','root','exam');
//设置字符集
mysqli_query($link,'set names utf8');
$search=isset($_GET['search'])?$_GET['search']:"";
//查询数据总条数
$sql1="select count(*) num from rikao_15 where c_mingcheng like '%$search%'";
$res1=mysqli_query($link,$sql1);
$arr1=mysqli_fetch_assoc($res1);
//获得数据总条数
$size=$arr1['num'];
//设置每页条数
$length=3;
//计算总页数
$pages=ceil($size/$length);
//传递页数
$page=isset($_GET['page'])?$_GET['page']:1;
//上一页,下一页
$last=$page-1<1?1:$page-1;
$next=$page+1>$pages?$pages:$page+1;
//偏移量
$offset=($page-1)*$length;
//写sql语句
$sql="select * from rikao_15 where c_mingcheng like '%$search%' limit $offset,$length " ;
//执行
$res=mysqli_query($link,$sql);
?>
<center>
<div id='div1'>
<input type="search" name="search" value="<?php echo $search?>">
<button οnclick="page(1)">搜索</button>
<table border=1>
<tr>
<td>全选<input type="checkbox" name="quanxuan" οnclick="quanxuan()"></td>
<td>自动序号</td>
<td>序列</td>
<td>名称</td>
<td>图片</td>
<td>作者</td>
<td>描述</td>
<td>权限</td>
<td>特定信息</td>
<td>操作</td>
</tr>
<?php
while($arr=mysqli_fetch_assoc($res)){
?>
<tr>
<td><input type="checkbox" name="box"value="<?php echo $arr['id']?>"></td>
<td><?php echo $arr['id']?></td>
<td><?php echo $arr['id']?></td>
<td><?php echo $arr['c_mingcheng']?></td>
<td><img src="<?php echo $arr['c_filename']?>" alt="" width=150/></td>
<td><?php echo $arr['c_author']?></td>
<td><?php echo $arr['c_desc']?></td>
<td><?php
if($arr['c_quanxuan']==1){
echo '是';
}else{echo '否';}
?>
</td>
<td><?php echo $arr['c_infor']?></td>
<td>
<a href="javascript:del(<?php echo $arr['id']?>)">删除</a>
<?php
if($arr['c_quanxuan']==1){
?>
<a href="upload.php?id=<?php echo $arr['c_filename']?>">下载</a>
<?php
}else{
?>
<a href="javascript:fun1()">下载</a>
<?php
}
?>
</td>
</tr>
<?php
}
?>
<tr>
<td>全选<input type="checkbox" name="xuan" οnclick="xuan()" ></td>
<td colspan=9>
<button οnclick="Quan()">全选</button>
<button οnclick="Fan()">反选</button>
<button οnclick="Bu()">全不选</button>
<button οnclick="Pi()">批量删除</button>
<button οnclick="Tian()">添加</button>
</td></tr>
</table>
<a href="javascript:page(1)">首页</a>
<a href="javascript:page(<?php echo $last?>)">上一页</a>
<a href="javascript:page(<?php echo $next?>) ">下一页</a>
<a href="javascript:page(<?php echo $pages?>)">尾页</a>
<?php echo $page?>/<?php echo $pages?> 总共<?php echo $size?>条数据
</div>
</center>
<script type="text/javascript">
function page(page){
var search = document.getElementsByName('search')[0].value;
var ajax = new XMLHttpRequest();
ajax.open('get','ajax.php?page='+page+'&search='+search);
ajax.send();
ajax.onreadystatechange = function(){
if(ajax.readyState==4 &&ajax.status == 200){
document.getElementById('div1').innerHTML=ajax.responseText;
}
}
}
function del(id){
//var search = document.getElementsByName('search')[0].value;
var ajax = new XMLHttpRequest();
ajax.open('get','del.php?id='+id);
ajax.send();
ajax.onreadystatechange = function(){
if(ajax.readyState==4 &&ajax.status == 200){
//alert(ajax.responseText);
if(ajax.responseText==1){
alert('删除成功');
location.href='ajax.php';
}else{
alert('删除失败');
location.href='ajax.php';
}
}
}
}
/*function del(id){
//var search = document.getElementsByName('search')[0].value;
var ajax = new XMLHttpRequest();
ajax.open('get','del.php?id='+id);
ajax.send();
ajax.onreadystatechange = function(){
if(ajax.readyState==4 &&ajax.status == 200){
//document.getElementById('div1').innerHTML=;
//alert(ajax.responseText);
}
}
}*/
//上全选
function quanxuan(){
var quanxuan=document.getElementsByName('quanxuan')[0]
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
if(quanxuan.checked==true){
box[i].checked=true;
}else{
box[i].checked=false;
}
}
}
//下全选
function xuan(){
var xuan=document.getElementsByName('xuan')[0]
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
if(xuan.checked==true){
box[i].checked=true;
}else{
box[i].checked=false;
}
}
}
//全选按钮
function Quan(){
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
box[i].checked=true;
}
}
//全不选
function Bu(){
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
box[i].checked=false;
}
}
//反选
function Fan(){
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
box[i].checked=!box[i].checked;
}
}
//添加
function Tian(){
location.href='rikao.php';
}
//批量删除
function Pi(){
var str="";
var box=document.getElementsByName('box')
for(var i=0;i<box.length;i++){
if(box[i].checked==true){
str=str+','+box[i].value;
}
}
str=str.substr(1);
var ajax = new XMLHttpRequest();
ajax.open('get','del.php?id='+str);
ajax.send();
ajax.onreadystatechange = function(){
if(ajax.readyState==4 &&ajax.status == 200){
//alert(ajax.responseText);
if(ajax.responseText==1){
alert('删除成功');
location.href='ajax.php';
}else{
alert('删除失败');
location.href='ajax.php';
}
}
}
}
function fun1(){
alert('该下载只支持会员');
}
</script>
原生的搜索分页
最新推荐文章于 2021-03-11 06:27:50 发布