0

I have code that worked before so i copied and pasted into new PDO as I am upgrading my website.

It displays all images in one row, even though i have told it after 4th image in row crete new row and sart putting images below the row above.

<?php

$query = 'SELECT * FROM tblgallery_images ';
$stmt = $dbh->prepare($query);
$stmt->execute();

$counter = 0;
$numberperrow = 4; 

while($row = $stmt->fetch()) {
  $name = $row['imagename'];

  if($counter < $numberperrow)
  {

    echo 'image here';
    $counter = $counter + 1;

  }else{

    echo '<br>';//NEXT ROW INSERTED

    $counter = 0;
    echo 'image here';

 }

}

?>

I need 4 images per row for as many images I have in my table

2
Contributors
4
Replies
22
Views
4 Years
Discussion Span
Last Post by minitauros
0

I have 7 to test, what it does is thor everything in one row no matter what, i see all 7 in the row, it does not break or go down to next row.

Edited by branding4you: clear

0

I dont believe this ....

while($row = $stmt->fetch()) {
  $name = $row['imagename'];
  if($counter < $numberperrow)
  {
    echo 'image here';
    $counter = $counter + 1;
  }else{
    echo '<br>';//NEXT ROW INSERTED
    $counter = 0;
    echo 'image here';
 }
}

Changed it by removing the $name = $row['imagename']; and using it in the row when its created like this ...

while($row = $stmt->fetch()) {


if($counter < $numberperrow)
{

    echo '<a href=img_store/'.$row['imagename'].' data-lightbox=Edenheim title=Edenheim ><img src=img_store/thumb/thumb_'.$row['imagename'].'></a>';

    $counter = $counter + 1;
    echo ' ';

}else{

    echo '<br>';
    $counter = '0';

    echo '<a href=img_store/'.$row['imagename'].' data-lightbox=Edenheim title=Edenheim ><img src=img_store/thumb/thumb_'.$row['imagename'].'></a>';
    echo ' ';
}

}

Now it works ... how is that possible ? I dont know. When i echoe'd numbers with images the number displayed correct but images were all in the same row.
Gueess it could have been the image <td> or soemething!
Oh well so we learn

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.