<?php
session_start();
include("cn.php");
$cn=new mysqli($host,$usrname,$posswd,$sjk);
if(isset($_SESSION['a'])){
}
else{
echo "<script> window.alert('请您先登入') ;</script>";
header('Location:logim.php');}
//删除
if(isset($_GET['id'])){
$carrent2=$_GET['id'];
$str="DELETE FROM `workes` WHERE `id`='$carrent2'";
mysqli_query($cn,"DELETE FROM `workes` WHERE `id`=$carrent2");
}?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数据库</title>
<style>
body{
background-color: rgb(115, 115, 55);
font-size: 14px;
}
h1{
color: orange;
text-align: center;
font-size: 30px;
}
table{
border-collapse: collapse;
width: 100%;
}
th{
width: 40px;
height: 20px;
background-color: rgb(151, 198, 182);
color: rgb(104, 26, 140);
text-align: center;
font-size: 22px;
}
table td,th{
text-align: center;
border: 1px solid rgb(77, 151, 207);
}
td{
font-size: 18px;
}
</style>
</head>
<body>
<h1>22级数据库管理系统</h1>
<form method="get" action="index.php?page1=1">
查询姓名<input type="text" name="name" <?php
echo 'value="'.$_POST['na'].'"'; ?>">
性别<select name="sex">
<option value="男和女"<?php if($_POST['sex']=='男和女')echo 'selected';?>>男和女</option>
<option value="男"<?php if($_POST['sex']=='男')echo 'selected';?>>男</option>
<option value="女" <?php if($_POST['sex']=='女')echo 'selected';?>>女</option>
<?php
$sex=$_POST['sex'];
if($_POST['sex']!='男和女'){
$se="AND `sex`='$sex'";
}
var_dump($sex);
?>
</select>
<select name="dir">
<?
$dir=$_POST['dir'];
$result1=mysqli_query($cn,'SELECT DISTINCT `directory` FROM `shangban`');
//查询workes表的内容以table的形式输出
echo "<option value='mr'>全部部门</option>";
while($r=$result1->fetch_assoc()){
$na=$_POST['dir'];
echo '<option value="'.$r['directory'].'"';
if($na==$r['directory']){
echo " selected"; }
echo '>'.$r['directory'].'</option>';}
if($_POST['dir']!='mr'){
$mr="AND `directory`='$na'";
}
echo '</br>';
?>
</select>
地址:<input type="text" name="address" <?php ;echo 'value="'.$_POST['address'].'"'; ?>>
<input type="submit" name="tj" value="查询" >
<a href="tianjia.php">添加</a>
</form>
</br>
<?php
if($cn->connect_error){
die("数据库连接失败").$cn->connect_error;
}
else{
//var_dump($sex);
//var_dump($na);
if(isset($_POST['tj'])||isset($_POST['name'])||isset($_POST['address'])||isset($_GET['page1'])){
// var_dump($_POST['name']);
//var_dump($_GET['page1']);
$name=$_POST['name'];
$add=$_POST['address'];
if($_POST['sex']!='男和女'&&$_POST['sex']!=null||$_POST['dir']!='mr'&&$_POST['dir']!=null){
$cont=" where name LIKE '{$name}%' $se $mr AND address LIKE '%{$add}%'";
}else{
$cont="where name LIKE '{$name}%'AND address LIKE '%{$add}%'";
}
$str1="SELECT * FROM `shangban` {$cont}";
$result=$cn->query($str1);
$num=$result->num_rows;
//var_dump($num);
$pagesize=5;
$totalpage=ceil($num/$pagesize);
//var_dump($totalpage);
if(isset($_GET['page1'])){
$carrent1=$_GET['page1'];
}
else{$carrent1=1;}
//当页开始记录
$index=($carrent1-1)*$pagesize;
$str="SELECT * FROM `shangban` {$cont} LIMIT {$index},{$pagesize}";
// echo $str;
$result=$cn->query($str);
// var_dump($result);
if(($result->num_rows)>0){
//查询shangban表的内容以table的形式输出
echo'<table><tr><th>编码</th><th>名字</th><th>性别</th><th>电话</th><th>移动电话</th><th>部门</th><th>职员</th><th>地址</th><th>邮箱</th><th>备注</th><th>修改</th><th>删除</th></tr>';
while($r=$result->fetch_assoc()){
echo "<tr><td>{$r['id']}</td>";
echo "<td>{$r['name']}</td>";
echo "<td>{$r['sex']}</td>";
echo "<td>{$r['phone']}</td>";
echo "<td>{$r['telephone']}</td>";
echo "<td>{$r['directory']}</td>";
echo "<td>{$r['staff']}</td>";
echo "<td>{$r['address']}</td>";
echo "<td>{$r['email']}</td>";
echo "<td>{$r['remark']}</td>";
echo "<td><a href='xiugai.php?diu={$r['id']}'>修改</a></td>";
echo "<td><a href='index.php?id={$r['id']}'>删除</a></td></tr>";
}
echo '</table>';}
else{
echo "无输出结果";
}
for($j=1;$j<=$totalpage;$j++){
echo "<a href='index.php?page1={$j}'> {$j} </a>";
}
}
else{
$str1="SELECT * FROM `shangban` ";
$result=$cn->query($str1);
$num=$result->num_rows;
//var_dump($num);
$pagesize=5;
$totalpage=ceil($num/$pagesize);
if(isset($_GET['page'])){
$carrent=$_GET['page'];
}
else{$carrent=1;}
//当页开始记录
$index=($carrent-1)*$pagesize;
$str="SELECT * FROM `shangban` LIMIT {$index},{$pagesize}";
//var_dump($str);
$result=$cn->query($str);
if(($result->num_rows)>0){
//查询shangban表的内容以table的形式输出
echo'<table><tr><th>编码</th><th>名字</th><th>性别</th><th>电话</th><th>移动电话</th><th>部门</th><th>职员</th><th>地址</th><th>邮箱</th><th>备注</th><th>修改</th><th>删除</th></tr>';
while($r=$result->fetch_assoc()){
echo "<tr><td>{$r['id']}</td>";
echo "<td>{$r['name']}</td>";
echo "<td>{$r['sex']}</td>";
echo "<td>{$r['phone']}</td>";
echo "<td>{$r['telephone']}</td>";
echo "<td>{$r['directory']}</td>";
echo "<td>{$r['staff']}</td>";
echo "<td>{$r['address']}</td>";
echo "<td>{$r['email']}</td>";
echo "<td>{$r['remark']}</td>";
echo "<td><a href='xiugai.php?diu={$r['id']}'>修改</a></td>";
echo "<td><a href='index.php?id={$r['id']}'>删除</a></td></tr>";
}
echo '</table>';}
else{
echo "无输出结果";
}
for($i=1;$i<=$totalpage;$i++){
echo "<a href='index.php?page={$i}'> {$i} </a>";
}
}}
?>
</body>
</html>