MYSQL :小案例金山词霸

<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Online Dictionary</title>
</head>
<body>
<img src="icon.jpg" style="margin-left: 300px"/>

<h1>查询英文</h1>

<form action="word.php" method="post" ;>
    请输入英文:<input type="text" name="enword"/>
    <input type="hidden" name="type" value="search1"/>
    <input type="submit" value="查询"/>
</form>

<h1>查询中文</h1>

<form action="word.php" method="post" ;>
    请输入中文:<input type="text" name="chword"/>
    <input type="hidden" name="type" value="search2"/>
    <input type="submit" value="查询"/>
</form>
</body>
</html>

<?php
header("content-type:text/html;charset=utf-8");
require_once "F:/WAMP/www/Hanshunping/SqlTool.class.php";
if (isset($_POST['type'])) {
    echo "TYPE<br>";
    $type = $_POST['type'];
} else {
    echo "NO TYPE EXISTS<br>";
}
if ($type == 'search1') {
    if (isset($_POST['enword'])) {
        $en_word = $_POST['enword'];
    } else {
        echo "BLANK input";
    }
    //$en_word需要引号;精确查询;
    $sql = "select * from words where enword='" . $en_word . "' limit 0,1";
    $database = "test003";
    $sqlTool = new SqlTool($database);
    $res = $sqlTool->execute_dql($sql);
    if ($row = mysqli_fetch_assoc($res)) {
        echo $en_word . "----中文意思:" . $row['chword'];
    } else {
        echo "No WORD";
    }

}
if ($type == 'search2') {
    if (isset($_POST['chword'])) {
        $ch_word = $_POST['chword'];
    } else {
        echo "BLANK input";
    }
    //模糊查询;like语句;
    $sql = "select * from words where chword like '%" . $ch_word . "%' ";
    echo $sql;
    $database = "test003";

    $sqlTool = new SqlTool($database);
    $res = $sqlTool->execute_dql($sql);
    //判断是否取出数据;
    if (mysqli_affected_rows($sqlTool->conn) > 0) {
        //因为要查询多个单词,这里用while循环;并且不再用limit        while ($row = mysqli_fetch_assoc($res)) {
            echo "<br>" . $ch_word . "----英文意思:" . $row['enword'];
        }

    } else {
        echo "nonononono";
    }
    echo "<br>" . $ch_word;
}
mysqli_free_result($res);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值