Multiple column HTML Table From Single Column Text File In PHP
<p>I have a simple working PHP script to write an HTML table from a text file that contains a single column of data that contains HTML links. This writes the data horizontally in a row across 5 or 6 columns as I want it to. But I am looking to set up a script with a loop that will take this list of data and input it into the table until it finishes the data list, so that I do not have to hard code each table cell individually. Just let the script create each table cell, at 5 or 6 columns across (whichever I need for this specific table), go to the next row, etc., until it runs out of data. The data in the data file will be added to on a regular basis, so the table will not be of a certain fixed length forever. I am using the echo command so that I can add some more HTML formatting later on. </p>

<p>Even though my existing script is simple and it works, if you can think of a better way of doing what I am trying to do, all suggestions are appreciated. </p>

<p>Thanks in advance, Stan...</p>

<p>PHP code follows:</p>

<pre><code>    &lt;?php
    $item = @fopen('linklist.txt', "r");

    if ($item) { while (!feof($item)) { $lines[] = fgets($item, 4096); } fclose($item); }

    echo'
    &lt;TABLE border="1"&gt;
    &lt;TR&gt;

    &lt;TD&gt;'.($lines[1]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[2]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[3]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[4]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[5]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[6]).'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;TR&gt;
    &lt;TD&gt;'.($lines[7]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[8]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[9]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[10]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[11]).'&lt;/td&gt;
    &lt;TD&gt;'.($lines[12]).'&lt;/td&gt;
    &lt;/tr&gt;

    &lt;!-- And So On, And So On, ETC --&gt;

    &lt;/table&gt;'

    ?&gt;
</code></pre>
