Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Loop/Count Output Display Help

Asked Modified Viewed 820 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

I have this quirky problem/need in my bootstrap_tabs infusion. First of all I took code from my Avatar Studio to read the uploaded images directory to get the uploaded filenames. Here is the function.
function loadTabImgs($dir) {
   $ignoreTabImgs = '.|..|.htaccess|index.php|.tmp';
   $tab_images = makefilelist(TAB_FOLDER.$dir, $ignoreTabImgs, true, 'files', '.png,.gif,.jpg,.jpeg');
   return (isset($tab_images)) ? $tab_images : false;
}
...and here is the page/portion where it is used.
            $tab_images = loadTabImgs(TAB_FOLDER);
      if (is_array($tab_images) && count($tab_images) > 0) {
      echo "<div align='center'><h4><strong>Uploaded Image Names For Textarea</strong></h4></div>n";
      echo "<div align='center'><table align='center' border='1'><tr>n";
      $i = 0;
         foreach($tab_images as $img_name) {
      echo "<td><b>$img_name</b></td>n";
      $i++;
   }
}
      echo "</tr></table></div>n";
Here are 2 images of the resultant output (tbl1.jpg) and what I need it to be (tbl2.jpg). Of course the cells would all be the same width on tbl2.jpg; this is just an image.

I can't figure out how to code the script to generate rows of 6 images. I know this should be a simple matter of looping and counting but I haven't been able to get it to work right.
Edited by Grimloch on 12-04-2022 15:55,
Grimloch attached the following image:
Image not found Image not found
0 replies

4 posts

D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Based on the counter $i mod 6 = 0 insert a </tr> <tr>
1 reply
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

OK; got it figured out. There's probably an easier way to do it but this works just fine and does not generate errors at all on 9.10.20.
            $tab_images = loadTabImgs(TAB_FOLDER);
      if (is_array($tab_images) && count($tab_images) > 0) {
      echo "<div align='center'><table align='center' border='1'><tr>n";
      echo "<td bgcolor='#840000' colspan='6' align='center'><span style='color:white;'><h4><strong>Uploaded Image Names For Textarea</strong></h4></span></td></tr><tr>n";
      $i = 1;
         foreach($tab_images as $img_name) {
      echo "<td bgcolor='#B7DBFF' align='center'><b>$img_name&nbsp;</b></td>n";
if ($i == 6 || $i ==12 || $i ==18) {
      echo "</tr><tr>n";
}
      $i++;
   }
}
      echo "</tr></table></div>n";
I really can't see anyone ever uploading more than 24 images for the tabs. Here is the output image.
Edited by Grimloch on 12-04-2022 20:51,
Grimloch attached the following image:
Image not found
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

If you replace ($i == 6 || $i ==12 || $i ==18) by ($i % 6 == 0)

Then it works for every multiply of 6

That's what I meant
Edited by douwe_yntema on 12-04-2022 21:42,
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I knew there had to be a better way; thanks douwe it works great !!
Grimloch attached the following image:
Image not found
0 replies

Labels

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet