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

  • Home
  • SEARCH
  • 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 7827217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:46:03+00:00 2026-06-02T09:46:03+00:00

How would I add echoing table headers to my current code? I’m a little

  • 0

How would I add echoing table headers to my current code?

I’m a little lost on how to do it because $lines[0] only prints my header row yet when I do an if statement to echo <th> if $lines[0] else echo <tr> it echos out with multiple empty <th>‘s so I’m a little lost if anyone could help.

function schedule_gen()
{
    //set file
    $filename='schedule.txt';
    //open
    $handler=fopen('schedule.txt','r');
    //read through file
    $file=fread($handler,filesize($filename));

    //start table creation
    echo "<table id='schedule_table'>"; 

    //split into array by return\linefeed
    $lines=explode("\r\n",$file);

    //loop through rows
    for($i=0;$i<count($lines);$i++) 
    { 
        //if not blank then print row
        if($lines[$i]!=""&&$lines[$i]!=" ")
        {

            echo "<tr class='schedule_row'>"; 

            //split into array by commas
            $items=explode("\t",$lines[$i]);
            //loop through cells 
            for($j=0;$j<count($items);$j++) 
            { 
                 //if not blank then print cell
                 if($items[$j]!=""&&$items[$j]!=" ")
                 {
                     echo "<td class='schedule_cell'>".$items[$j]."</td>"; 
                 }
            } 
            echo "</tr>"; 
        }
     } 
     echo "</table>"; 
     //end table creation

     fclose($handle);
     //close file 
}

Example of schedule.txt:

Employee/schedule restrictions  Thur 4/26   Fri 4/27    Sat 4/28    Sun 4/29    Mon 4/30    Tue 5/1 Wed 5/2
Administrative                          
Assistant   8a-4    8a-4    no  no  8a-4p   8a-4p   8a-4p

QC Team -Manager                            
QC team / no Tues or Sat    8a-4    8a-4    no  8a-4p   8a-4p   no  8a-4p
QC team 6p-2a   6p-2a   6p-2a   no  6p-2a   6p-2a
  • 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-06-02T09:46:05+00:00Added an answer on June 2, 2026 at 9:46 am

    Not too sure if I read your question right but is this what you need?

    function schedule_gen()
    {
    //set file
    $filename='schedule.txt';
    //open
    $handler=fopen('schedule.txt','r');
    //read through file
    $file=fread($handler,filesize($filename));
    
    //start table creation
    echo "<table id='schedule_table'>"; 
    
    //split into array by return\linefeed
    $lines=explode("\r\n",$file);
    
    //loop through rows
    for($i=0;$i<count($lines);$i++) 
    { 
    //if not blank then print row
    if($lines[$i]!=""&&$lines[$i]!=" ")
    {
    $t_type="td";
    if($i==0){$t_type="th";}
    
    //split into array by commas
    $items=explode("\t",$lines[$i]);
    //loop through cells 
    for($j=0;$j<count($items);$j++) 
    { 
    //if not blank then print cell
    if($items[$j]!=""&&$items[$j]!=" ")
    {
    echo "<$t_type class='schedule_cell'>".$items[$j]."</$t_type>"; 
    }
    } 
    echo "</tr>"; 
    }
    } 
    echo "</table>"; 
    //end table creation
    
    fclose($handle);
    //close file 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a function that would add a time delay between 2 lines of
I am trying to get some sample code on how I would add rows
I am looking for the Lotus Script which would add X-header to the outgoing
Im trying to add a little code to an already made thumbnail plugin. Basically
I have this code, which would add one bundle product with the ID of
I would like to add level classes to each li when echoing the results
I wish to add a new column to a table, usually I would add
I'd like to write a gmail extension that would add a button on the
I'm using Elmah with ASP.NET and wondering how I would add custom data, such
I thought every time you do a flash[:notice]=Message it would add it to the

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.