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 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集