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

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>


0 个评论

要回复文章请先登录注册