Connecting Tech Pros Worldwide Forums | Help | Site Map

How to output from file into table???

matt
Guest
 
Posts: n/a
#1: Jul 17 '05
I have this bit of code that opens a file, reads it line by line, and
prints the filename into an image on screen, so i get a big list of
images on the page.

However I want it to output into a table so I can have 2 photos side by
side as it goes through, is there any way of manipulating the code to
output one line into one cell and the next line into the next cell then
back to the first cell again???

<?
$data = file('gallery/captions');

foreach ($data as $line)
{
list ($q, $a) = explode('|' , trim($line) );
echo "<img src='gallery/images/$q' height=100><br>";
echo "$a<br>";
}

?>

Michal Wozniak
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to output from file into table???


[color=blue]
> <?
> $data = file('gallery/captions');
>
> foreach ($data as $line)
> {
> list ($q, $a) = explode('|' , trim($line) );
> echo "<img src='gallery/images/$q' height=100><br>";
> echo "$a<br>";
> }
>
> ?>[/color]

<?
$data = file('gallery/captions');
echo "<table border=1>";
foreach ($data as $line)
{
list ($q, $a) = explode('|' , trim($line) );
echo "<td><img src='gallery/images/$q' height=100><br>";
echo "$a</td>";
$ee++;
//2 - row
if($ee%2==0) echo "<tr>";


}
echo "</table>";
?>

--
Michal Wozniak



Steve
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to output from file into table???


Michal Wozniak wrote:[color=blue][color=green]
>><?
>>$data = file('gallery/captions');
>>
>>foreach ($data as $line)
>>{
>> list ($q, $a) = explode('|' , trim($line) );
>> echo "<img src='gallery/images/$q' height=100><br>";
>> echo "$a<br>";
>>}
>>
>>?>[/color]
>
>
> <?
> $data = file('gallery/captions');
> echo "<table border=1>";
> foreach ($data as $line)
> {
> list ($q, $a) = explode('|' , trim($line) );
> echo "<td><img src='gallery/images/$q' height=100><br>";
> echo "$a</td>";
> $ee++;
> //2 - row
> if($ee%2==0) echo "<tr>";[/color]
Tidier is
if($ee%2==0) echo "</tr><tr>";
[color=blue]
>
> }
> echo "</table>";[/color]
echo "</tr></table>";

Steve[color=blue]
> ?>
>
> --
> Michal Wozniak
>
>
>[/color]
Erwin Moller
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to output from file into table???


matt wrote:
[color=blue]
> I have this bit of code that opens a file, reads it line by line, and
> prints the filename into an image on screen, so i get a big list of
> images on the page.
>
> However I want it to output into a table so I can have 2 photos side by
> side as it goes through, is there any way of manipulating the code to
> output one line into one cell and the next line into the next cell then
> back to the first cell again???
>
> <?
> $data = file('gallery/captions');
>
> foreach ($data as $line)
> {
> list ($q, $a) = explode('|' , trim($line) );
> echo "<img src='gallery/images/$q' height=100><br>";
> echo "$a<br>";
> }
>
> ?>[/color]

Hi,

Just make the table:

<table border=1>
<?
$data = file('gallery/captions');
foreach ($data as $line)
{
list ($q, $a) = explode('|' , trim($line) );
?>
<tr>
<td>
<img src='gallery/images/<?= $q ?>' height=100>
</td>
<td>
<?= $a ?>
</td>
</tr>
<?
}
?>
</table>

Regards,
Erwin Moller
Closed Thread