Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
subjectlist.php 5.68 KB
Copy Edit Raw Blame History
友人A authored 2023-04-09 10:12 . 已完成
<?php
include_once('config/config.php');
$LoginAdmin = auth();
// 当前页
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
// 每页显示多少条数据
$limit = 3;
// 显示多少个页码
$size = 3;
// 查询admin数据表的数据总数
$countSql = "SELECT COUNT(*) AS c FROM `stu_subject`";
$Count = find($countSql);
// 调用分页函数
$ShowPage = page($page,$Count['c'],$limit,$size);
// 偏移量 -> 索引值
$start = ($page - 1) * $limit;
// 查询数据
// $Sql = "SELECT * FROM `pre_job` ORDER BY `id` DESC LIMIT $start,$limit";
$Sql = "SELECT * FROM `stu_subject` ORDER BY `id` DESC LIMIT $start,$limit";
$Data = all($Sql);
if($_POST)
{
// 获取ajax的操作
$action = $_POST['action'];
if($action == 'del')
{
$id = $_POST['id'];
$Sql = "SELECT * FROM `stu_subject` WHERE `id` = '$id'";
$admin = find($Sql);
if(!$admin)
{
error('删除的学科不存在');
}
// 删除函数 返回ajax请求的数据
$result = delete('subject',"`id` = '$id'");
if($result)
{
success('删除该科目成功');
}else{
error('删除该科目失败');
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once('common/meta.php');?>
</head>
<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body>
<!--<![endif]-->
<!-- 引用头部 -->
<?php include_once('common/header.php') ?>
<!-- 引用菜单 -->
<?php include_once('common/nav.php') ?>
<div class="content">
<div class="header">
<h1 class="page-title">学科列表</h1>
</div>
<ul class="breadcrumb">
<li><a href="index.php">Home</a> <span class="divider">/</span></li>
<li class="active">SubjectList</li>
</ul>
<div class="container-fluid">
<div class="row-fluid">
<div class="btn-toolbar">
<button class="btn btn-primary" onClick="location='subjectadd.php'"><i class="icon-plus"></i>新增学科</button>
</div>
<div class="well">
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>学科名</th>
<th>学分</th>
<th style="width: 26px;"></th>
</tr>
</thead>
<tbody>
<?php foreach($Data as $item) {?>
<tr>
<td><?php echo $item['id'];?></td>
<td>
<?php echo $item['name'];?>
</td>
<td>
<?php echo $item['credit'];?>
</td>
<td>
<a href="subjectedit.php?id=<?php echo $item['id'];?>"><i class="icon-pencil"></i></a>
<a href="#myModal" role="button" data-id="<?php echo $item['id'] ?>" class="del" data-toggle="modal"><i class="icon-remove"></i></a>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<?php echo $ShowPage;?>
<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">删除</h3>
</div>
<div class="modal-body">
<p class="error-text"><i class="icon-warning-sign modal-icon"></i>确认该学科?</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
<button class="btn btn-danger" id="del" data-del-id data-dismiss="modal">删除</button>
</div>
</div>
<?php include_once('common/footer.php'); ?>
</div>
</div>
</div>
</body>
</html>
<?php include_once('common/script.php');?>
<script>
/*
1、data-id 获取并且传到弹出窗里
2、点击删除执行ajax
*/
$('.del').click(function() {
// 点击哪个就获取哪个id
var id = $(this).data('id')
// 赋值到删除按钮
$('#del').data('del-id', id)
})
// 删除按钮
$('#del').click(function() {
// 获取需要删除的id
var id = $(this).data('del-id')
$.ajax({
url: 'subjectlist.php',
type: 'post',
data: {
// $_POST['id']
// 'id':id
id,
'action': 'del'
},
dataType: 'json',
success: function(res) {
if (res.code === 1) {
alert(res.msg)
location.reload()
} else {
alert(res.msg)
}
}
})
})
</script>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化