Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:16:45+00:00 2026-05-23T02:16:45+00:00

My script is retrieving images from a database and displaying the images in a

  • 0

My script is retrieving images from a database and displaying the images in a table. I want to have the table have 4 columns of images before it breaks the row and starts over. I’ve found some helpful answers on this forum but after re-organizing and fussing with the code it displays every image in it’s own table rather than adding the row breaks after every fourth image. I’m running on little sleep, but hopefully a second pair of eyes could help me spot the problem.

<?php
include_once "connect.php";
$userid = $_SESSION['id'];
$albumid = $_GET['album'];
$pic = mysql_query("SELECT * FROM `pictures` WHERE userid='$userid' AND
albumid='$albumid'");
$i = 0;
echo "<center><table width='50%'><tr>";
while($row = mysql_fetch_assoc($pic)){
$id = $row["id"];
$thumbnail = $row["thumbnail"];
echo "<td><a href='viewphoto.php?photo=$id'><img src='$thumbnail'>  
</a></td>";
if ($i && $i%4 == 0) echo '</tr><tr>';
$i++;
echo "</tr><tr>";
}
echo "</table> </center>";
?>

Fiddled around a little bit and

while($row = mysql_fetch_assoc($pic)){
$id = $row["id"];
$thumbnail = $row["thumbnail"];
if ($i && $i%4 == 0) echo '</tr><tr>'; 
$i++;
echo "<td><a href='viewphoto.php?photo=$id' rel='facebox'><img src='$thumbnail'>
</a></td>";}

worked like a charm.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:16:45+00:00Added an answer on May 23, 2026 at 2:16 am

    $i was initialized inside the loop. and Table also bring outside.

    see the code below.

         <?php
            include_once "connect.php";
            $userid = $_SESSION['id'];
            $albumid = $_GET['album'];
            $pic = mysql_query("SELECT * FROM `pictures` WHERE userid='$userid' AND
            albumid='$pic'");
           $i = 0;
        echo "
        <center><table width='50%'><tr>";
    
            while($row = mysql_fetch_assoc($image)){
        $id = $row["id"];
        $thumb = $row["thumb"];
        $date = strftime("%b %d, %Y", strtotime($row['date']));
        echo "<td><img src='$thumbnail'></td>";
    
        if ($i && $i%4 == 0) echo '</tr><tr>';
          $i++;
        }
        echo "</table> </center>";
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code that generate some images with urls associated from database:
I have written a script in MATLAB, where I am retrieving rows and columns
I am writing a script that is retrieving information from file places.sqlite (history) and
I'm creating multiple form retrieving data from jquery. after that i want to work
I'm retrieving information about resources from a MySQL database using PHP. The information about
I have made a script that runs with no glitch on Firefox. I'm retrieving
I am retrieving a product description value stored in database from admin through textarea
i have a problem when it comes to retrieving value from jQuery to php.i
I have a script that loads info from external XML file and inserts it
I have implemented the ThickBox Plugin and I am retrieving the content from using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.