Disappearing array

Hi,

the following will display the images 4 per row, but an array per row will disappear from the results

example: 9 pictures, 01, 02, 03, 04, 05, 06, 07, 08, 09

01 02 03 04
06 07 08 09

05 disappeared. What part of the code is causing this? Thanks

[php] <?php
include (“connect.php”);
$query=“select file_link from image”;
$result=mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$result_array[]=$row[‘file_link’];

}

$counter=1;
echo “

”;
echo “”;

foreach ($result_array as $link) {

if ($counter <= 4) {
echo “

”;
$counter ++;
} else {
echo “”;
$counter=1;
}

}

?>[/php]

”;
echo “”;
echo “

In your code, if $counter == 5, you just reset $counter to 1 and start new table row. But you do not output image in this case. Here is a correct code:

[php]$counter=0;
echo “

”;

foreach ($result_array as $link) {
if($counter%4==0) echo ‘

’;
echo “”;
if($counter%4==3) echo ‘’;
$counter++;
}
// remaining empty cells (if any)
$k=$counter%4;
if($k){
for($i=$k;$i<4;$i++){
echo ‘’;
}
echo ‘’;
}

echo ‘

’;[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service