Connecting Tech Pros Worldwide Help | Site Map

How to output from file into table???

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 10:48 AM
matt
Guest
 
Posts: n/a
Default How to output from file into table???

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>";
}

?>

  #2  
Old July 17th, 2005, 10:48 AM
Michal Wozniak
Guest
 
Posts: n/a
Default 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



  #3  
Old July 17th, 2005, 10:49 AM
Steve
Guest
 
Posts: n/a
Default 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]
  #4  
Old July 17th, 2005, 10:49 AM
Erwin Moller
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.