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 8223685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:47:44+00:00 2026-06-07T14:47:44+00:00

I have a PHP function where an undefined number of images in a directory

  • 0

I have a PHP function where an undefined number of images in a directory are being output to the browser. The images are being read in to an object. The issue I’m having is how the images are presented. I want to put them in a table, four <td> cells in a row. Here is the code:

function displayThumbList(){

   $tlist = $this->getThumbList();
   $i = 0;
   $e = 3;
   echo '<table width="400px" border=1><tr>';
   foreach ($tlist as $value) {
    echo "<td width=\"90px\" height=\"50px\"><a href=\"showImage.php?id=".$this->getBaseName($value,$this->thumbPrefix)."\" target=\"imgHolder\"><img class=\"timg\" src=\"thumbnail/".$value."\" alt=\"a\" /></a></td>";
    $_GET['imagefocus'] = $this->getBaseName($value,$this->thumbPrefix);

  //here is where the condition for adding a <tr> tag is evaluated 
  if ($i == $e){
       echo '<tr>';
     }

  $i++; //increments by 1 with each foreach loop
 }
 echo '</table>';
}

The first time $i(third time through foreach loop) is equal to $e, the process adds the as expected. I need $e to increment by 3 AFTER each time the condition is met.

The number of images are undefined. If there are 21 images in the directory, $i would increment 21 times and $e should increment 7 times adding 3 with each increment (3,6,9,12,15 etc).

I guess I’m looking for an increment based on another loop condition (every time equality is reached). Any thoughts?
rwhite35

  • 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-07T14:47:47+00:00Added an answer on June 7, 2026 at 2:47 pm
    if ($i == $e){
       echo '<tr>';
       $e = $e + 3;
     }
    

    Alternatively, use modulo, something like

    if ($i % 3 == 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP function that takes a variable number of arguments (using func_num_args()
I am trying to have a function grab an object from a php file
I have a PHP function that extract dat of an invoice from DB. The
I have a php function which returns JSON in response to a ajax request
I have a PHP function that builds a JSON array via $jsonArray= array(); for
i have a php function which returns a random json encoded color <?php function
I have a PHP function that requires can take 3 parameteres... I want to
I have a PHP function which inserts multiple records into MySQL: function commit_purchase($asset_type_ID, $org_ID,
I have a PHP function that I want to make available publically on the
Is it possible to have a PHP function that is both recursive and anonymous?

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.