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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:51:08+00:00 2026-06-10T05:51:08+00:00

I’m just beginning with PHP and mySQL (about 4 days in now) and have

  • 0

I’m just beginning with PHP and mySQL (about 4 days in now) and have been trying to find a fix to this problem…

I have a set of items that I am returning from a mySQL database. I have these flowing into a set of 4 “ul” columns with a class of “models” with it dividing the number of results by 4 and returning “li”s and cannot figure out why I have a phantom empty “ul” at the end. I have tried putting the “ul”s into a foreach statement but that didn’t return the desired results either.

Thanks for any help.

Here is the php:

<grid>
  <ul class="models">
    <?php

    $c = count($model);

    $s = ($c / 4); // change 4 to the number of columns you want to have.

    $i=1;

    foreach ($model as $models): ?>
      <li>
        <a href="model/?id=<?php htmlout($models['sn']); ?>" class="id<?php htmlout($models['sn']); ?>">
          <div class="<?php htmlout($models['callout']); ?>"></div>
          <div id="description">
             <h2><?php htmlout($models['firstname']); ?> <?php htmlout($models['lastname']); ?>
             </h2>
             <h3><span class="number">40</span> photo sets</h3>
             <h3><span class="number">756</span> images</h3>
             <p><?php htmlout($models['rightstext_left']); ?>
                <?php htmlout($models['firstname']); ?>
                <?php htmlout($models['rightstext_right']); ?>
             </p>
          </div>
       </a>
    </li>
    <?php if($i != 0 && $i % $s == 0)
    {
        ?>
  </ul>
  <ul class="models">
    <?php
    }
    $i++; ?>
    <?php endforeach; ?>
  </ul>
</grid>

The HTML

<grid>    
**excluded**
<ul class="models">
<li>
   <a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
   <div class="exclusive"></div>
   <div id="description">
      <h2>Model 19</h2>
      <h3><span class="number">1</span> attribute</h3>
      <h3><span class="number">6</span> attributes</h3>
      <p>textleft name textright</p>
    </div>
   </a>
</li>
<li>
   <a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
   <div class="exclusive"></div>
   <div id="description">
      <h2>Model 19</h2>
      <h3><span class="number">1</span> attribute</h3>
      <h3><span class="number">6</span> attributes</h3>
      <p>textleft name textright</p>
    </div>
   </a>
</li>
<li>
   <a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
   <div class="exclusive"></div>
   <div id="description">
      <h2>Model 19</h2>
      <h3><span class="number">1</span> attribute</h3>
      <h3><span class="number">6</span> attributes</h3>
      <p>textleft name textright</p>
    </div>
   </a>
</li>
<li>
   <a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
   <div class="exclusive"></div>
   <div id="description">
      <h2>Model 19</h2>
      <h3><span class="number">1</span> attribute</h3>
      <h3><span class="number">6</span> attributes</h3>
      <p>textleft name textright</p>
    </div>
   </a>
</li>
<li>
   <a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
   <div class="exclusive"></div>
   <div id="description">
      <h2>Model 19</h2>
      <h3><span class="number">1</span> attribute</h3>
      <h3><span class="number">6</span> attributes</h3>
      <p>textleft name textright</p>
    </div>
   </a>
</li>
</ul>

  • 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-10T05:51:10+00:00Added an answer on June 10, 2026 at 5:51 am

    I changed your logic a little bit. Since you work with modulo, it would make more sense to start with $i = 0

    You want to be sure to have an integer when you’re doing modulo operations, so try:

    $s = ceil($c / 4);
    

    Then use it in your if to test if you’re at the end of a <ul> element, and make sure you don’t create one on the last iteration:

    <?php if ($i % $s == $s - 1 && $i != $c - 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.