zoukankan      html  css  js  c++  java
  • 表单关键字查询写法

    <!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>
    </head>

    <body>

    <hl>表单的关键字查询</h1>

    <form action="Untitled-1.php" method="post">

    <div>
    请输入查询的名字:<input type="text" name="name" />
    <input type="submit" value="查询" />
    </div>

    </form>

    <table width="100%" border="1" cellpadding="0" cellspacing="0">

    <tr>
    <td>ID</td>
    <td>名字</td>
    <td>性别</td>
    <td>生日</td>
    <td>地址</td>
    </tr>

    <?php

    //实现两个逻辑
    //1.如果没有POST数据,查询所有
    //2.如果有POST数据,根据条件查询

    $db = new MySQLi("localhost","root","密码","数据库名字"); 

    $tj = " 1 = 1 ";              //默认条件
    if(!empty($_POST))
    {
    $name = $_POST['name'];
    $tj = " name like '%{$name}%' ";
    }

    //将条件拼接到SQL语句
    $sql = "select * from 表名 where {$tj}";
    $result = $db -> query($sql);

    while($arr = $result -> fetch_row())
    {
    //关键字的特殊显示
    $name; $arr[1];
    $str = str_replace($name,"<mark>{$name}</mark>",$arr[1]);

    echo "<tr>
    <td>{$arr[0]}</td>
    <td>{$str}</td>
    <td>{$arr[2]}</td>
    <td>{$arr[3]}</td>
    <td>{$arr[5]}</td>
    </tr>";
    }

    ?>

    </table>

    </body>
    </html>

    效果图:

    查询张

  • 相关阅读:
    Java计算某个日期是一年中的第几天
    k8s-CentOs7.x 搭建集群(1)(kubelet 1.19.2)
    k8s-PV、PVC(7)
    k8s-Volumes(6)
    k8s-Scale、Rolling Update(5)
    k8s-Service介绍(4)
    k8s-部署AspNetCore应用(3)
    k8s-搭建Dashboard(2)
    AspNetcore搭配Serilog利用docker发布CentOs7
    CentOs7 搭建http服务器访问文件目录
  • 原文地址:https://www.cnblogs.com/yyy251/p/6434477.html
Copyright © 2011-2022 走看看