如何移动表列?

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?

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>

I think the problem is that you are not opening and closing the tag correctly.

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

in that part it would print something like this.

    <tr>
   <td>something</td>
  <td>something</td>
<tr>
  <td>something</td>
 <td>something</td>
<tr>
   <td>something</td>
<td>something</td>

You would need to open and close the tr tag inside the loop or outside.