代码 4-46 简化后的“result.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"; ?>


0 个评论

要回复文章请先登录注册