Jump to content

Need Help Displaying txt or csv into tables...


about2flip

Recommended Posts

Hi:

 

I am a php newbie, and I am trying to display data put into a txt or csv file into tables. I am using this code:

 

<?php

$filename = "data.txt";

$id = fopen($filename, "r");

while ($data = fgetcsv($id, filesize($filename),";"))

$table[] = $data;

fclose($id);

echo '<table cols="2" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">';

 

foreach($table as $row)

{

echo "<tr>";

foreach($row as $data)

echo "<td>$data</td>\n";

echo "</tr>\n";

}

echo "</table>\n"

?>

 

It displays correctly, but I need the food in one column and the price per in another or if there is some way I can tab to make it look neater.

 

Shrimp Salad $7.25 Per Person

Albacore Tuna Salad $4.00 Per Person

Hand Picked Chicken Salad $5.00 Per Person

 

Thanks for your help.

 

This is the result I get from the txt file

 

Shrimp Salad      $7.25 Per Person

Albacore Tuna Salad  $4.00 Per Person

Hand Picked Chicken Salad $5.00 Per Person

 

I want to tab between the name of the sandwich and price

 

This is the line that prints the code, so where would i put \t to push the price over more to the right?

 

echo "<td>$data</td>\n";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.