Reply to Re: PHP Foreach HELP!

Your name:

Reply:


Posted by Erwin Moller on 11/15/74 11:34

matt wrote:

> I have this bit of code, that isn't valid, and I need some help getting
> it to work... Currently, I get an error because I am calling the next()
> function within a foreach loop. I am opening a flat file with data in
> the format of:
>
> 01|data1|data2
>
> 01 Being Gallery Name, data1 being the filename, data2 being photo
> caption.
>
> Basically I need to look at the line from the text file, and if the
> first 2 digits do not match the gallery I have specified, then move on
> to the next line, completely ignoring the first line... Code follows:
>
>
> I would appreciate any help...
>
> <?
>
> $gallery = 03;
>
> $data = file('gallery.txt');

OK, you now have an array called $data with all lines.

>
> echo "<table border=0 width=500 align=center>";
> foreach ($data as $line)
> {
> list ($g, $q, $a) = explode('|' , trim($line) );
> if ( $g != $gallery ) next($line);
> else
> {

Why do you test for something you do not care about?
And what is next() in this context?
It is wrong.

Try this:
if ($g == $gallery ){
// print out here
}


> echo "<td width=50% valign=top><img src='/gallery/$q'
> width=220><br>"; echo "$a<br>";
> echo "<a href=\"/gallery/$q\">Enlarge</a><br><br></td>";
> $ee++;
> //2 - row
> if($ee%2==0) echo "<tr>";
> }
> echo "</table>";
>
> }
>
>
> ?>


regards,
Erwin Moller

[Back to original 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

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