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

  • Home
  • SEARCH
  • 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 8887307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:46:29+00:00 2026-06-14T21:46:29+00:00

I am trying to display images from a MySQL database in a table, three

  • 0

I am trying to display images from a MySQL database in a table, three to a row. I’m able to do it but the problem is that my original code had it so if you had only one row in your MySQL table, it would run the code three times per row anyhow and leave two empty <td>‘s (and leave one empty one if you had two rows). I was trying to run a loop that said if you have less than three rows remaining, run the loop for that many times and quit. I’ve looked over this code again and again and talked it out to myself but can’t seem to find where the problem is. The error I get is that it runs the loop infinitely. I have two rows currently so what it’s doing is running the loop twice per <tr> but forever.

I thought that adding 3 to the $rowcounter would stop the loop. The $rowcounter starts at 0, the loop runs through. 3 is added to the $rowcounter (making it 3) which would make it greater than $num_rows_temp (which would be two since there’s only two rows) and the loop would not execute. Again, the problem must be in the first while loop because it’s generating new rows in my table infinitely…Is there a reason that $rowcounter would not have had 3 added to it?

(Also, please ignore the variable declarations under the fetch_arrays. These are going to be using for functionality once I get the loop working. They look frivolous right now though…)

Can someone please help me figure out what I have wrong here? Thanks so much.

<?php
$rowcounter=0;

if($num_rows_temp==0){
echo "No pictures yet!";
}
else{
//BEGIN JOB POSTING                             
    while($rowcounter<=$num_rows_temp){
        $remaining=$num_rows_temp-$rowcounter;
        $counter=1;
        echo "<tr>";
        //IF THE REMAINING AMOUNT OF ROWS IS LESS THAN THREE, RUN THE WHILE LOOP
        //FOR THE AMOUNT OF REMAINING ROWS
        if ($remaining>0 && $remaining<3){
            while($counter<=$remaining){
                $row_temp = mysqli_fetch_array($result_temp, MYSQL_NUM);
                $id = $row_temp[0];
                $location = $row_temp[1];
                $name = $row_temp[2];
                $email = $row_temp[3];
                echo "<td>
                <a href='".$location."'>
                <img class=\"g-thumbnail\" src='".$location."' width=\"200\" height=\"200\" />
                </a>
                </td>";
                $counter++; 
             } //END WHILE
          } //END IF
          else{
              while($counter<=3){
                  $row_temp = mysqli_fetch_array($result_temp, MYSQL_NUM);
                  $id = $row_temp[0];
                  $location = $row_temp[1];
                  $name = $row_temp[2];
                  $email = $row_temp[3];
                  echo "<td>
                  <a href='".$location."'>
                  <img class=\"g-thumbnail\" src='".$location."' width=\"200\" height=\"200\" />
                  </a>
                  </td>";
                  $counter++;   
               } //END WHILE
           } //END ELSE
           echo "</tr>";
           $rowcounter+3;
        } //END WHILE
    } //END ELSE
?>
  • 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-06-14T21:46:31+00:00Added an answer on June 14, 2026 at 9:46 pm

    Your $rowcounter+3; is not increasing $rowcounter. Change to-

    $rowcounter +=3;
    

    As is $rowcounter+3; would only work if you are echo’ing

    echo $rowcounter+3;  // would echo 3 each time
    

    Also you are setting $counter inside your while loop

    while($rowcounter<=$num_rows_temp){
        $remaining=$num_rows_temp-$rowcounter;
        $counter=1;
    

    So even though you increase it by doing

    $counter++;
    

    It will be set back to 1 once it starts the while() loop again. You need to declare this before the while().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display images from a database table to my dataGridView control. Other
I have been trying to display image from database using php but i am
I'm trying to display video from a webcam. I capture the images from the
From any specific Post, I am trying to display all images, with their corresponding
I am trying to produce images without gamma information so that IE8 can display
I'm developing an application that shall receive images from a camera device and display
I'm trying to display Tiff Images that I have a byte array for. I
I'm trying to get the very last table data row. I have this code:
I am trying to display 8 pictures from a column that contains filenames within
I am trying to display images vertically 5 per row using php and I

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.