You are here: Need help with my code reading flat file into HTML table « PHP Programming Language « IT news, forums, messages
Need help with my code reading flat file into HTML table

Posted by JackM on 01/21/06 19:23

I need a little guidance putting a script together. I'm trying to read a
list of image links from a text file (not a database) and display them
in a table on my page. I want to display them in rows of four. I can get
my script to work to display the images but I can't figure out how to do
two things:
1. How do I get only one image into each table data entry?
2. How do I get it to create blank table data entries for any amount
less than 4 left at the end? (Example: there are 9 images and I want it
in the last table row to put the one image remaining and three blank
table data entries)

Here's what I've got so far:

$file = "links.txt";
$result = file_get_contents("links.txt");
$lines = count(file("$file"));

$tdcount = 1;
$numtd = 4; // number of cells per row
echo "<table border=2>";

$arr=array($result);
foreach ($arr as $value)
{
if ($tdcount == 1) echo "<tr>";
echo "$value";
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
} // close up the table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo "</table>";
?>


When I echo $result and $lines at the top and exit the script, they both
show as they should so the file is being read properly. When I echo
$arr, all I get is the word "array". And when I run the script, the 9
images appear in rows of 4, 4, and 1 which is good but the table appears
below the image links, not containing them as I want.

Can anyone show me the error of my ways? It's probably something dumb
but I've worked on this for two days now trying all kinds of variations
and can't get it to work. Thanks for any help.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация