韩顺平php mysql扩展库在线词典案例

mainview.php

<html>
<head>
<title>在线词典</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>//设置编码
</head>
<img src="ciba.png"/>
<h1>查询英文</h1>
<form action="worProcess.php" method="post">
请输入英文:<input type="text" name="enword"/>
<input type="hidden" value="search1" name="type"/>
<input type="submit" value="查询"/>
</form>
<form action="worProcess.php" method="post">
请输入中文:<input type="text" name="chword"/>
<input type="hidden" value="search2" name="type"/>//交给同一个文件要注意区分value的值,不同的文件不需要区分。
<input type="submit" value="查询"/>
</form>
</html>

worProcess.php

<?php
require_once 'SqlTool.class.php';
header("content-type:text/html;charset=utf-8");
//接收type 
if(isset($_POST['type'])){
	$type=$_POST['type'];


}else{
 echo "输入为空";
 echo "<a href="mainview.php">返回重新查询</a>";

}

if($type=="search1"){

//接收英文单词
//$en_word=$POST['enword'];
if(isset($POST['enword'])){

$en_word=$POST['enword'];

}else{

 echo "输入为空";
 echo "<a href="mainview.php">返回重新查询</a>";
}
//看看数据库中有没有这条记录
//用什么查什么

$sql="select chword from words where  enword='".$en_word."' limt 0,1";
//设计表
//查询 使用工具类SqlTool.class.php 上一节课
$sqlTool = new SqlTool();
$res=$sqlTool->execute_sql($sql);
if($row=mysql_fetch_assos($res)){
	echo $en_word."对用的中文意思".$row[chword];
	echo "<br/><a href="mainview.php">返回重新查询</a>";


}else{
echo "查询到没有这个结果";
echo "<br/><a href="mainview.php">返回重新查询</a>";

}
mysql_free_result($res);




}else if($type=="search2"){

//接收中文单词
//$en_word=$POST['enword'];
if(isset($POST['chword'])){

$ch_word=$POST['chword'];

}else{

 echo "输入为空";
 echo "<a href="mainview.php">返回重新查询</a>";

//echo $ch_word;//验证中文是否有乱码问题验证接收的中文

$sql="select enword from words where  chword like '%".$ch_word."%' ";
//echo "sql=$sql";//测试$sql语句
//设计表
//查询 使用工具类SqlTool.class.php 上一节课
$sqlTool = new SqlTool();
$res=$sqlTool->execute_sql($sql);
if(mysql_num_rows($res)>0){
while($row=mysql_fetch_assos($res)){
	echo "<br/>".$cn_word."对用的英文意思".$row[chword];
	echo "<br/><a href="mainview.php">返回重新查询</a>";


}
}else(
	echo "查询到没有这个结果";

)

echo "<br/><a href="mainview.php">返回重新查询</a>";
mysql_free_result($res);

}


?>

数据库信息

数据库信息
create database worddb;
use worddb;
set names utf8;
show variables like ‘%char%’;
drop table words;

create table words(

id int primary key auto_increament,
enword varchar(32) not null,
chword varchar(256) not null

)
insert into words(enword,chword)values('boy','男孩');
insert into words(enword,chword)values('shcool','学校');
insert into words(enword,chword)values('niddle school','高中学校');

猜你喜欢

转载自blog.csdn.net/weixin_43345480/article/details/89673300