Forum Moderators: coopster
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 written so far:
template.inc
<tr>
<td><? echo $result;?></td>
<td><? echo $result;?></td>
<td><? echo $result;?></td>
<td><? echo $result;?></td>
</tr>
test.php
<?php
$result = file_get_contents("image.txt");
?>
<table border="2">
<?php
for ($i=0, $n=sizeof($result); $i<$n; $i++) {
include("template.inc");
}
?>
</table>
image.txt
<A href="Aticket-73.jpg"><img src="./thumbnails/tn_Aticket-73.jpg" width="152" height="71" alt="A ticket 1973"></a>
<A href="Aticket.jpg"><img src="./thumbnails/tn_Aticket.jpg" width="152" height="75" alt="A ticket"></a>
<A href="Bticket-73.jpg"><img src="./thumbnails/tn_Bticket-73.jpg" width="152" height="71" alt="B ticket 1973"></a>
<A href="Bticket.jpg"><img src="./thumbnails/tn_Bticket.jpg" width="152" height="71" alt="B ticket"></a>
<A href="Cticket-73.jpg"><img src="./thumbnails/tn_Cticket-73.jpg" width="152" height="71" alt="C ticket 1973"></a>
<A href="Cticket.jpg"><img src="./thumbnails/tn_Cticket.jpg" width="152" height="87" alt="C ticket"></a>
<A href="Dticket-73.jpg"><img src="./thumbnails/tn_Dticket-73.jpg" width="152" height="71" alt="D ticket 1973"></a>
<A href="Dticket.jpg"><img src="./thumbnails/tn_Dticket.jpg" width="152" height="93" alt="D ticket"></a>
<A href="Eticket-73.jpg"><img src="./thumbnails/tn_Eticket-73.jpg" width="152" height="71" alt="E ticket 1973"></a>
Can anyone help me? Thanks.
<?php
$result = file_get_contents("image.txt");
$tdcount = 1;
$numtd = 4; // number of cells per row
echo "<table>";
$arr=array($result);
foreach ($arr as $value)
{
if ($tdcount == 1) echo "<tr>";
echo "$value"; // display as you like
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
} // time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td> </td>";
$tdcount++;
}
echo "</tr>";
}
echo "</table>";
?>
<?php
$file = "filename.txt"; //specify your filename
$cols=4;
$pos=0;
$result = file($file);
$lines = count($result);
$spaces=($lines%$cols>0)? 1 : 0;
$rows=floor($lines/$cols)+$spaces;
echo "<table border='2' width='100%'>\n";
for($i=0;$i<$rows;$i++){
echo "<tr>\n";
for($j=0;$j<$cols;$j++){
if(isset($result[$pos])){
echo "\t<td align='center'>".trim($result[$pos])."</td>\n";
}
else{
echo "\t<td> </td>\n";
}
$pos++;
}
echo "</tr>\n";
}
echo "<table>";
?>