代码 5-2 创建新数据库myterm的SQL语句

教材代码韩林涛 发表了文章 • 0 个评论 • 928 次浏览 • 2020-07-06 15:16 • 来自相关话题

CREATE DATABASE myterm     DEFAULT CHARACTER SE ...查看全部
CREATE DATABASE myterm    
DEFAULT CHARACTER SET utf8    
DEFAULT COLLATE utf8_general_ci;


代码 5-1 用于创建数据库的SQL语句

教材代码韩林涛 发表了文章 • 0 个评论 • 1121 次浏览 • 2020-07-06 15:15 • 来自相关话题

CREATE TABLE `stiterm`.`TermData`     (    ...查看全部
CREATE TABLE `stiterm`.`TermData`    
(    
`ID` INT(5) NOT NULL AUTO_INCREMENT ,    
`zh_CN` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,    
`en_US` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,    
PRIMARY KEY (`ID`)    
)    
ENGINE = InnoDB    
CHARSET=utf8    
COLLATE utf8_general_ci;


代码 4-46 简化后的“result.php”代码

教材代码韩林涛 发表了文章 • 0 个评论 • 1187 次浏览 • 2020-07-06 15:14 • 来自相关话题

result.php<?php include "shared/head.php"; ?>  ...查看全部

result.php

<?php include "shared/head.php"; ?>      
<table width="89%" border="1">      
<tbody>      
<tr>      
<td width="21%">      

<strong>序号</strong>

      
</td>      
<td width="31%">      

<strong>中文</strong>

      
</td>      
<td width="46%">      

<strong>英文</strong>

      
</td>      
</tr>      
<?php include "shared/conn.php"; ?>        
<?php      
mysqli_select_db( $conn,"stiterm" );    
$query =$_POST["query"];    
$sql = "SELECT ID, zh_CN, en_US FROM termdata WHERE zh_CN LIKE '%$query%' or en_US LIKE '%$query%'";    
mysqli_query($conn,"set names 'utf8'");    
$getterm = mysqli_query($conn,$sql);    
if(! $getterm )    
{    
echo "无法获取术语数据,请检查问题";    
}    
else      
{    
while ($row = mysqli_fetch_array($getterm, MYSQLI_ASSOC))    
{    
$row['zh_CN']=preg_replace("/$query/i", "<font color=red><b>$query</b></font>",$row['zh_CN']);    
$row['en_US']=preg_replace("/$query/i", "<font color=red><b>$query</b></font>",$row['en_US']);    
echo "<tr>      
                        <td width='21%'>      
                        

{$row["ID"]}

      
                        </td>      
                        <td width='31%'>      
                        

{$row["zh_CN"]}

      
                        </td>      
                        <td width='46%'>      
                        

{$row["en_US"]}

      
                        </td>      
                      </tr>";    
}    
}    
mysqli_close($conn);    
?>      
</tbody>      
</table>      
<?php include "shared/foot.php"; ?>


代码 4-45 简化后的“search.php”代码

教材代码韩林涛 发表了文章 • 0 个评论 • 846 次浏览 • 2020-07-06 15:13 • 来自相关话题

search.php<?php include "shared/head.php"; ?> &nbs ...查看全部

search.php

<?php include "shared/head.php"; ?>      
<form action="result.php" method="POST">      
<table>      
<tr>      
<td>      
<input type="text" name="query" placeholder="请输入检索词" >      
</td>      
<td>      
<button type="submit">搜索</button>      
</td>      
</tr>      
</table>      
</form>      
<?php include "shared/foot.php" ?>


代码 4-44 用于代码共享的“conn.php”代码

教材代码韩林涛 发表了文章 • 0 个评论 • 906 次浏览 • 2020-07-06 15:12 • 来自相关话题

conn.php<?php       $dbhost = "l ...查看全部

conn.php

<?php      
$dbhost = "localhost";  //数据库所在主机地址      
$dbuser = "root";      //登录数据库所用的用户名      
$dbpass = ""; //登录数据库所用的用户名密码      
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);    
if(!$conn )    
{    
die("无法连接服务器,错误代码为: " . mysqli_connect_error());    
}    
//     else      
//   {      
//     echo "服务器连接成功!";      
//   }      
?>


代码 4-43 用于代码共享的“foot.php”代码

教材代码韩林涛 发表了文章 • 0 个评论 • 1031 次浏览 • 2020-07-06 15:10 • 来自相关话题

foot.php</body>     </html> ...查看全部

foot.php

</body>    
</html>


代码 4-42 用于代码共享的“head.php”代码

教材代码韩林涛 发表了文章 • 0 个评论 • 874 次浏览 • 2020-07-06 15:09 • 来自相关话题

head.php<!DOCTYPE html>     <html> &nb ...查看全部

head.php

<!DOCTYPE html>    
<html>    
<head>    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
<title>STITERM</title>    
</head>    
<body>


代码 4-38 用于高亮显示查询结果的“result.php” 代码

教材代码韩林涛 发表了文章 • 0 个评论 • 1018 次浏览 • 2020-07-06 15:07 • 来自相关话题

result.php<!DOCTYPE html>       <htm ...查看全部

result.php

<!DOCTYPE html>      
<html>      
<head>      
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
<title>STITERM</title>      
</head>      
<body>      
<table width="89%" border="1">      
<tbody>      
<tr>      
<td width="21%">      

<strong>序号</strong>

      
</td>      
<td width="31%">      

<strong>中文</strong>

      
</td>      
<td width="46%">      

<strong>英文</strong>

      
</td>      
</tr>      
<?php      
$dbhost = "localhost";  //数据库所在主机地址      
$dbuser = "root";      //登录数据库所用的用户名      
$dbpass = ""; //登录数据库所用的用户名密码      
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);    
if(!$conn )    
{    
die("无法连接服务器,错误代码为: " . mysqli_connect_error());    
}    
//     else      
//   {      
//     echo "服务器连接成功!";      
//   }      
mysqli_select_db( $conn,"stiterm" );    
$query =$_POST["query"];    
$sql = "SELECT ID, zh_CN, en_US FROM termdata";    
mysqli_query($conn,"set names 'utf8'");    
$getterm = mysqli_query($conn,$sql);    
if(! $getterm )    
{    
echo "无法获取术语数据,请检查问题";    
}    
else      
{    
while ($row = mysqli_fetch_array($getterm, MYSQLI_ASSOC))    
{    
$row['zh_CN']=preg_replace("/$query/i", "<font color=red><b>$query</b></font>",$row['zh_CN']);    
$row['en_US']=preg_replace("/$query/i", "<font color=red><b>$query</b></font>",$row['en_US']);    
                 echo "<tr>      
                        <td width='21%'>      
                        

{$row["ID"]}

      
                        </td>      
                        <td width='31%'>      
                        

{$row["zh_CN"]}

      
                        </td>      
                        <td width='46%'>      
                        

{$row["en_US"]}

      
                        </td>      
                      </tr>";    
}    
}    
mysqli_close($conn);    
?>      
</tbody>      
</table>      
</body>      
</html>


代码 4-36 用于执行SQL查询语句的代码

教材代码韩林涛 发表了文章 • 0 个评论 • 1053 次浏览 • 2020-07-06 11:51 • 来自相关话题

result.php<!DOCTYPE html>   <html>   ...查看全部

result.php

<!DOCTYPE html>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>STITERM</title>  
</head>  
<body>  
<table width="89%" border="1">  
<tbody>  
<tr>  
<td width="21%">  

<strong>序号</strong>

  
</td>  
<td width="31%">  

<strong>中文</strong>

  
</td>  
<td width="46%">  

<strong>英文</strong>

  
</td>  
</tr>  
<?php  
$dbhost = "localhost";  //数据库所在主机地址  
$dbuser = "root";      //登录数据库所用的用户名  
$dbpass = ""; //登录数据库所用的用户名密码  
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(!$conn )
{
die("无法连接服务器,错误代码为: " . mysqli_connect_error());
}
//     else  
//   {  
//     echo "服务器连接成功!";  
//   }  
mysqli_select_db( $conn,"stiterm" );
$sql = "SELECT zh_CN, en_US FROM termdata";
mysqli_query($conn,"set names 'utf8'");
$getterm = mysqli_query($conn,$sql);
if(! $getterm )
{
echo "无法获取术语数据,请检查问题";
}
else  
{
while ($row = mysqli_fetch_array($getterm, MYSQLI_ASSOC))
{
echo "<tr>  
                        <td width='21%'>  
                        

{$row["ID"]}

  
                        </td>  
                        <td width='31%'>  
                        

{$row["zh_CN"]}

  
                        </td>  
                        <td width='46%'>  
                        

{$row["en_US"]}

  
                        </td>  
                      </tr>";
}
}
mysqli_close($conn);
?>  
</tbody>  
</table>  
</body>  
</html>


孩子出生了,我给她开发了一个吃喝拉撒记录网站

回复

脑洞大开韩林涛 回复了问题 • 1 人关注 • 1 个回复 • 1299 次浏览 • 2020-06-18 12:36 • 来自相关话题