批量删除与查询

批量删除

主界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="bootstrap/js/jquery-1.11.2.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

</head>

<body>
<form action="./pldelete.php" method="post">
<table class="table table-striped">
  <caption>人员信息展示</caption>
  <thead>
    <tr>
      <th><input type="checkbox" id="ckall" />代号</th>
      <th>姓名</th>
      <th>性别</th>
      <th>民族</th>
      <th>生日</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
      <?php
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "select info.code,info.name,sex,nation.name,birthday from info,nation where info.nation=nation.code";
    $result = $db->query($sql);
    if($result){
        $arr = $result->fetch_all();
        foreach($arr as $v){
            $sex = $v[2]?"":"";
            echo "<tr>
      <td><input class='ck' type='checkbox' name='ck[]' value='{$v[0]}' />{$v[0]}</td>
      <td>{$v[1]}</td>
      <td>{$sex}</td>
      <td>{$v[3]}</td>
      <td>{$v[4]}</td>
      <td><a href='./delete.php?code={$v[0]}' onclick=\"return confirm('确认删除么?')\"><button type='button' class='btn btn-primary btn-sm'>删除</button></a><a href='./xiugai.php?code={$v[0]}' ><button type='button' class='btn btn-primary btn-sm'>修改</button></a></td>
    </tr>";
        }
    }
    ?>
  </tbody>
</table>

<div><input type="submit" value="批量删除" /><a href="./tianjia.php">添加数据</a></div>
</form>
<script type="text/javascript">
var ckall = document.getElementById("ckall");
ckall.onclick = function(){
    var xz = ckall.checked;
    var ck = document.getElementsByClassName("ck");
    for(var i=0;i<ck.length;i++){
        ck[i].checked = xz; 
    }
}
</script>
</body>
</html>

 

批量删除处理界面

<?php
$arr = $_POST["ck"];

//delete from info where code in('p001','p002','p003')

$str = implode("','",$arr);
$sql = "delete from info where code in('{$str}')";

$db = new MySQLi("localhost","root","123","mydb");
$result = $db->query($sql);
if($result){
    header("location:main.php");
}else{
    echo "删除失败!";
}

 

查询

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0 auto; padding:0;}
</style>
</head>

<body>
<h1 style="width:128px;">查询数据</h1>
<form action="./1.php" method="post">
<div style="width:560px">请输入名称:<input id="name" type="text" name="name" /> 请输入系列号:<input id="code" type="text" name="code" />
<input type="submit" value="提交" />
</div>
</form>
<br />
<table border="1" cellpadding="0" cellspacing="0" style="width:98%">
    <thead>
        <th>代号</th>
        <th>名称</th>
        <th>系列</th>
        <th>油耗</th>
        <th>价格</th>
    </thead>
    
    <tbody>
        <?php
            require_once "./page.class.php";
            $tj = "1=1";        //条件一,不输入时为全部显示
            $tj2 = "1=1";      //条件二,不输入时为全部显示
            $name = "";
            if(!empty($_POST["name"])){
                $name = $_POST["name"];
                $tj = " name like '%{$name}%'";
                }
            if(!empty($_POST["code"])){
                $code = $_POST["code"];
                $tj2 = " brand like '%{$code}%'";
                }
                
             $db = new MySQLi("localhost","root","123","ceshi");
            $sql = "select * from car where {$tj} and {$tj2}"; 
            $jieguo = $db->query($sql);
            if($jieguo){
                $arr = $jieguo->fetch_all();
                foreach($arr as $v){
                    $v[1];$name;
                    $carname= str_replace($name,"<span style='color:red'>{$name}</span>",$v[1]);   //关键字颜色
                    echo"<tr>
                    <td>{$v[0]}</td>
                    <td>{$carname}</td>
                    <td>{$v[2]}</td>
                    <td>{$v[4]}</td>
                    <td>{$v[7]}</td>
                    </tr>";
                    }
                }
        ?>
    </tbody>
</table>
</body>
</html>

 

posted @ 2018-02-21 15:53  桃花灬仙人  阅读(382)  评论(0编辑  收藏  举报