dopuzf0898 2013-08-13 19:55
浏览 16
已采纳

如何移动表列?

I want to display a text file on a table and assign some code for each record.

  • I can display the text file
  • I can assign the code for each record (not yet finish as still under development.)

However, I came to a problem. The table column is not match up for some reason.

This is what happened. Heading 3 (Pink colour) the fields do not match the table.

Below is my code:

<table border='1'>
<tr>
  <th>Heading 1</th>
  <th>Heading 2</th>
  <th>Heading 3</th>
</tr>

<?php           
$file=file('number.txt');       
foreach($file as $value){   
    $items = explode(" ", $value);
    echo "<tr>";
    echo "<td>$items[0]</td>";
    echo "<td>$items[1]</td>";
}

include("connect.php");//connect to the database.
$sql = mysql_query("select * from code5 where Status='Active' LIMIT 8");

if (mysql_num_rows($sql) > 0)
{
    while ($row = mysql_fetch_array($sql))
    {
        echo "<td>$row[Code]</td>";         
        echo "</tr>";
    }
}
?>
</table>

can someone spot what am I missing? or give me a hand on moving the table column?

Do I have to implement a CSS file to adjust it manually?

  • 写回答

2条回答 默认 最新

  • dongmuyan5638 2013-08-13 20:08
    关注

    If the lines in the file is matched with the rows in the database this should work

    <table border='1'>
    <tr>
      <th>Heading 1</th>
      <th>Heading 2</th>
      <th>Heading 3</th>
    </tr>
    
    <?php           
    $file=file('number.txt');       
    
    include("connect.php");//connect to the database.
    $result = mysql_query("select * from code5 where Status='Active' LIMIT 8");
    
    foreach($file as $value)
    {   
        $items = explode(" ", $value);
        echo "<tr>";
        echo "<td>$items[0]</td>";
        echo "<td>$items[1]</td>";
        if($row = mysql_fetch_array($result))
        {
            echo "<td>$row[Code]</td>";         
        }
        else
        {
            echo "<td>Empty?</td>";         
        }
        echo "</tr>";
    }
    ?>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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