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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:20:02+00:00 2026-05-21T02:20:02+00:00

So I know this is simple but I’ve been banging my head against the

  • 0

So I know this is simple but I’ve been banging my head against the wall for a while trying to figure it out. I want to show a ruler at the bottom of my loop on each one except the last one. I can get it to work if I have the exact number of records but not if I have less. For example if the max number to show is 10 but there are only 5 records I want the divider after the 4th record. Likewise, if there are 20 results but max is 10 I want it after the 9th.

        <?php $subscriberIDs = ba_getUsersByRole( 'subscriber' );
        // Loop through each user
        $i=0;
        $max = 10; //max number of results
        $total_users =count($subscriberIDs); //total number of records
        foreach($subscriberIDs as $user) : 
        if($i<=$max) : ?>

        <li>   
                       <?echo $user['data'];?>
        </li>

        <?php 
        if(($i < $total_user-1 && $max >= $total_users) || ($i < max-1 &&  $total_users <= $max)){echo "<hr>";}
    $i++;

        endif; 
        endforeach; ?
  • 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-21T02:20:02+00:00Added an answer on May 21, 2026 at 2:20 am
    // <hr> goes in every spot, but not on the last item, up to 10
    $position = min($max-1, count($subscriberIDs)-1);
    $i = 0;
    foreach($subscriberIDs as $user){
       echo '<li>' . $user['data'] . '</li>';
       if($i != $position){
           echo '<hr>';
       }
       $i++;
    }
    

    This takes the lesser of either $max-1 or count($subscriberIDs)-1, which by definition is will be the last item you’ll iterate over. If you have more than $max items, then this will be $max-1, if you have less than $max items, then this will be count(.)-1.

    Then, during the iteration, the if statement prints an <hr> so long as the current item is not the last item.

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

Sidebar

Related Questions

I know this is a simple question, but I can't figure it out. Consider
I know this is simple but I can't figure it out today and I
I know this should be simple but can't figure it out. Here's the code.
I know this is a simple question for someone out there, but I have
I know this is simple but my brain is fried from trying to solve
this should be really simple but I can just not figure it out at
I know this should be simple but I can't work it out. I have
I know this is simple but I am not able to get it right
I know this probably really simple but Im not sure what im doing wrong...
I know this is really simple but I cant find the docs for this

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.