Page 1 of 1

Text to html table?

Posted: Thu Dec 12, 2002 9:01 pm
by jrstark
I'm not even sure what to ask for here. I have several charts, for lack of a better word. They are currently hard coded as tables. One in particular is a TV schedule.

What I would like to do is keep the data in a text file. Then use PHP to pull this info into a correctly formatted table.

I found and modified some code that I thought would do this. However, what it did was lump all field0 items into one td, all field1, etc. I need each line of data to be a tr, with alternating background colors for easier reading.

This is my original page:
http://www.barntowire.com/DerbyTV.shtml

Here is my PHP attempt:
http://www.barntowire.com/newTV2.html

Here is a snippet of the code I used:
<td align="left"><font face="arial,helvetica" size="2"><?
$readfile = file("TVlist.txt");
for ($k=0; $k<=count($readfile)-1; $k++) {
$fields = split("\t",$readfile[$k]);
print("$fields[2]<br>");
}
?>
</font></td>

What is the best way to do something like this? This particular page gets updated rather frequently, usually I get a list of new programs that will go between existing items (to stay chronological). But I also get multi-column lists that need to be coded quickly, so would modify the same code for them.

Thanks!
Janine

Good luck.

Posted: Sun Dec 15, 2002 8:23 pm
by LostSoul
Here's a quick and dirty way to get what you need.

<?
$readfile = file("TVlist.txt");
$colorCount = 0;
for ($k=0; $k<=count($readfile)-1; $k++)
{
if($colorCount == '0')
{
$color = "#99CCFF";
$colorCount++;
}
else
{
$color = "#ffffff";
$colorCount = 0;
}
?>
<tr>
<td align="left" bgcolor="<? echo "$color"; ?>">
<font face="arial,helvetica" size="2">
<?
$fields = split("\t",$readfile[$k]);
print("$fields[2]<br>");
?>
</font>
</td>
</tr>
<?
}
?>