|
Posted by Steve on 10/21/20 11:34
> 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
> <?
>
> $gallery = 03;
>
> $data = file('gallery.txt');
>
> 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
> {
> 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>";
>
> }
>
>
> ?>
Don't mix foreach() and next(). Change the test around to avoid it, and
use break to quit the test after a successful match (make sure that
your data is sorted by gallery).
foreach ($data as $line)
{
// ...
if( $g == $gallery )
{
// ...do the table output here...
// then get out of the loop:
break;
}
}
// this should be outside the foreach() loop:
echo '</table>';
---
Steve
Navigation:
[Reply to this message]
|