dongpao5127 2012-08-19 04:12
浏览 21
已采纳

PHP表数据输出不是保留结构

I have a mySQL database, and I'm using PHP to grab it and display it in a HTML table. It's set up like this:

<table>
 <tr>
  <td>Title 1</td>
  <td>Title 2</td>
 </tr>

<?php

$i=0;
while ($i < $num) {

$col1=mysql_result($result,$i,"col1");
$col2=mysql_result($result,$i,"col2");

?>

 <tr>
  <td><?php echo $col1; ?></td>
  <td><?php echo $col2; ?></td>
 </tr>
</table>

<?php

  $i++;
  echo '<br />';
  }

?>

The problem: for the first set of data it pulls, the columns align with the titles. But for every repeating row after that, the columns are separated by one space, and don't align with their titles. It looks like this:

Title 1       Title 2

col1          col2

col1 col2
col1 col2

Sorry if the wording is confusing.

  • 写回答

4条回答 默认 最新

  • duanlinjian5819 2012-08-19 04:14
    关注

    You're closing the table inside the loop, try to pull the </table> outside of the loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算