duan198727 2015-05-02 09:02
浏览 71
已采纳

使用PHP以HTML格式从表格式获取和显示数据库中的数据

I have done with fetching and display the data. But the problem is ,its display the data of fetched row in the same row of html table. For example : i want to display like this

                  ID | Name | Desination
                   ......................
                   1 | ABC | Developer
                   2 | PQR | Tester
                   3 | XYZ | Developer

But its showing as -

                   ID | Name | Desination
                   ......................
                    1 | ABC | Developer   2 | PQR | Tester   3 | XYZ | Developer

I have done something like this-

$sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_desc FROM candidate ".$join.' where '.$condition;
$result = mysql_query($sql) or die(mysql_error()); 

Correct me with the display format of table.

 <div class="box-body table-responsive no-padding">
     <table class="table table-hover">
          <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Designation</th>
          </tr>
          <tr>
              <?php

                   If(mysql_num_rows($result)>0)
                   {
                     while($row=mysql_fetch_array($result))
                     {  

                ?>
                  <td><?php echo $row['cand_number']; ?></td> 
                  <td><?php echo $row['cand_fname']; ?></td> 
                  <td><?php echo $row['cand_desc']; ?></td> 
                <?php

                }
                }
                 ?>

              </tr>
       </table>
    </div>
  • 写回答

4条回答 默认 最新

  • dsjzmrz78089 2015-05-02 09:05
    关注

    You need to repeat row not column

     <?php
    If (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_array($result)) {
            ?>
            <tr>
                <td><?php echo $row['cand_number']; ?></td> 
                <td><?php echo $row['cand_fname']; ?></td> 
                <td><?php echo $row['cand_desc']; ?></td> 
            </tr>
            <?php
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条