dongzhan8620 2015-12-16 15:12
浏览 18

如何使用PHP和MySQL在一个表中显示搜索结果

I have the code to do the search. But the search results are not in the same table. All search results appear in a different table. How do I make them appear in one table?

screenshots :

    <?php if(isset($_POST['submit']))
    {
        if(empty($_POST['word'])){
        echo "<center>Title do not match. Please insert the correct title.</center>";}
    else {
        if(isset($_POST['word'])&& !empty($_POST['word']))
    {
    require 'config.php';   
    $word = $_POST['word'];
    $query="SELECT * FROM data WHERE word LIKE '%" . $word . "%'";
    $sql = $conn->query($query); ?>
    <?php if(!$sql)
    {
     echo "<center>No Record</center>";
     }
     ?>
    <table align="center" border="0" >
    <tr>
    <td width="900">
    <?php while($row = $sql->fetch_assoc()){
        $dataID = $row['dataID'];
        ?>                               
       <?php if($sql ==true){?> 


   <table class="table table-bordered table-hover table-striped">
      <tr>
        <td width="258" align="center" class="style5">TITLE</td>
        <td width="170" align="center" class="style5">MENTION</td>
        </tr>

      <tr>
       <td style="text-transform:uppercase" align="center"> <a href="admindisplay.php?id=<?php echo $row{'dataID'}?>"> <span style="text-transform:uppercase"><?php echo $row{'word'};?></span> </a></td>
        <td style="text-transform:uppercase" align="center"><span style="text-transform:uppercase"><?php echo $row{'mention'};?></span></td>

        </tr>
        <?php }}} ?>re
  • 写回答

4条回答 默认 最新

  • douyinmian8151 2015-12-16 15:17
    关注

    Move your table code outside of your loop, and only create a new row each time you loop. You were creating a new table each time you loop.

       <table class="table table-bordered table-hover table-striped">
          <tr>
            <td width="258" align="center" class="style5">TITLE</td>
            <td width="170" align="center" class="style5">MENTION</td>
            </tr>
     <?php while($row = $sql->fetch_assoc()){
            $dataID = $row['dataID'];
            ?>                               
           <?php if($sql ==true){?> 
    
    
    
          <tr>
           <td style="text-transform:uppercase" align="center"> <a href="admindisplay.php?id=<?php echo $row{'dataID'}?>"> <span style="text-transform:uppercase"><?php echo $row{'word'};?></span> </a></td>
            <td style="text-transform:uppercase" align="center"><span style="text-transform:uppercase"><?php echo $row{'mention'};?></span></td>
    
            </tr>
            <?php }}} ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)