How Can I Loop Through a Text File And Print it Out in Table?

I have a homework assignment in which I have been working on and am trying to figure out how to loop through a text file and print it out as an HTML table. It needs to be in a table row that is one spanned over 5 columns in the

I have wrote the while loop but I keep on getting errors. I used both Google and Yahoo to search for help for about 15-20 minutes but I couldn’t get enough help with the problem.

<?php

// declared and initialized handler variable
$handler = 0;

// set up error message in case the event_orders.txt tried to be opened at once
@$handler = fopen('event_orders.txt', 'a'); // used the fopen function to open up the event_orders.txt file for reading 
if (!$handler) // if statment to find out if the event_orders.txt was being accessed by another person and the to return error with custom output
{
echo "<p><strong>No orders pending. Please try again later.</strong></p>"; // custom output to let the person know that there are no orders pending
exit; // exit the if statement
}

?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Event Registration Orders</title>
<link href="assets/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="assets/styles.css" rel="stylesheet" type="text/css">

</head>

<body>

<div class="row">

  	<div class="col-md-8 col-md-offset-2">
    <p><a href="register.html">Order Now</a> | <a href="orders.php">View All Orders</a></p>
    
    <h2>List of all orders for this event</h2>
    <hr/>

      <table class="table table-striped table-hover">
              <thead>
                <tr>
                  <th>Date</th>
                  <th>Event Participant</th>
                  <th>Email</th>
                  <th>Tickets</th>
                  <th>Total</th>
                </tr>
              </thead>
              
              <tbody>
				  
			   
              	<tr>
                  <?php
				  				  
				  $handler = "event_orders.txt";
				  
			while (!feof($handler)) //while loop to write variable values into the event_orders.txt file
				  fwrite($handler, ); // writes data to event_orders.txt file as a new table row that has one column that is spanned over 5 columns 
				  fclose($handler); // closes the event_orders.txt file 
				  ?> 
				</tr>
				  
                </tr>
              </tbody>
              
              <tbody>

                    
              </tbody>
            </table>
            
    </div>
    
</div> 
</body>

</html>

OP, do not post duplicates of the same thing. You already have a thread going on this subject.

Different assignment based on what I compared.

@sean4fsu777

@$handler = fopen('event_orders.txt', 'a'); // used the fopen function to open up the event_orders.txt file for reading  

The comments do not match what this does. And you later reinitialize the $handler variable entirely.

You are right @astonecipher I don’t know which way is up. I am working on trying to fix four programming assignments in PHP & MySQL Programming Class, trying to study for my first exam in that class that I have to take before midnight tonight, and try to fix two Intermediate C++ programs that are also due tonight. And working 40 hours, went on a short anniversary trip over the weekend. And having some health issues. This may seem like a movie, but it is true. To say I am overwhelmed is the understatement of the year :slightly_smiling_face:

I’m going to leave it like it is for now, and get to it later when I can match this document with the correct assignment number. I do need to get back to it and learn the concepts a lot better. Thank you for helping so far.

Sponsor our Newsletter | Privacy Policy | Terms of Service