Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:21:48+00:00 2026-05-29T06:21:48+00:00

I have a simple working PHP script to write an HTML table from a

  • 0

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.

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.

Thanks in advance, Stan…

PHP code follows:

    <?php
    $item = @fopen('linklist.txt', "r");

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

    echo'
    <TABLE border="1">
    <TR>

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

    <!-- And So On, And So On, ETC -->

    </table>'

    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:21:49+00:00Added an answer on May 29, 2026 at 6:21 am
    <?php
    echo '<table border="1"><tr>';
    for($i=0; $i<sizeof($lines); $i++) {
        echo '<td>'.$lines[$i].'</td>';
        if(($i+1)%6==0 && $i!=sizeof($lines)-1) echo '</tr><tr>';
    }
    echo '</tr></table>';
    ?>
    

    Explanation:

    Repeats through each “line” and writes the <td>value</td>

    If a line is a multiple of 6, after writing the value, then close the row, and open another (unless it’s the last one, since it will close the row after the loop as well.

    (I assume you meant to start on $line[0], but if you really meant to start on $line[1], just change the $i=0; to $i=1;, remove the +1 in the row check, and change $i<sizeof to $i<=sizeof

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using this simple script to generate images from text: <?php header('Content-type:
I have a simple script which copies a file from one SMB mount to
I'm working with my simple PHP captcha algorithm ( http://www.source.ofitall.com/devel/captcha.php ) and I have
I have a simple Delphi program that I'm working on, in which I am
I have a relatively simple site that I'm working up for an intranet environment.
I have the a simple LinqToSQL statement that is not working. Something Like this:
I have a strange issue. I'm trying to write a simple php webpage on
I have a simple html form that I've added validation to using the JQuery
Trying to get a simple test perl script working. Have the following files/folder structure
I'm trying to write a simple PHP script which automatically sets up new etherpads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.