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

That should work.. :\ Are you sure there are over 4 images in your database?

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.

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

Haha ah well, luckily your problem is solved now ^^.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.