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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:25:29+00:00 2026-06-02T16:25:29+00:00

At the moment, with the code from below, I have the data shown like

  • 0

At the moment, with the code from below, I have the data shown like this:

http://img27.imageshack.us/img27/8083/29769986.jpg

but I want it to be shown like this:

http://img259.imageshack.us/img259/3233/24033830.jpg

The code for the data shown, as it is on the first image, is:

<div id="content">
  <?php foreach ($categories as $category) { ?>
  <div class="manufacturer-list">
    <div class="manufacturer-heading"><?php echo $category['name']; ?><a id="<?php echo $category['name']; ?>"></a></div>
    <div class="manufacturer-content">
      <?php if ($category['manufacturer']) { ?>
      <?php for ($i = 0; $i < count($category['manufacturer']);) { ?>
      <ul>
        <?php $j = $i + ceil(count($category['manufacturer']) / 4); ?>
        <?php for (; $i < $j; $i++) { ?>
        <?php if (isset($category['manufacturer'][$i])) { ?>
        <li><a href="<?php echo $category['manufacturer'][$i]['href']; ?>"><?php echo $category['manufacturer'][$i]['name']; ?></a></li>
        <?php } ?>
        <?php } ?>
      </ul>
      <?php } ?>
      <?php } ?>
    </div>
  </div>
  <?php } ?>
</div>

I order to get the “Hewlett-Packard” text under the “HTC” text, I’ve changed the “/ 4” into “/ 1”, but I have no idea how to make the data to be shown into three columns (like on the second picture), instead of one, as it is now (as shown on the first picture).

Thanks in advance.

EDIT: What I actually need, is to count and to do the calculation on this code:

<?php foreach ($categories as $category) { ?>
.
.
.
<?php } ?>

So it needs to count the number of categoris, do the calculations, and present the code between into three columns.

  • 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-02T16:25:31+00:00Added an answer on June 2, 2026 at 4:25 pm

    Try this one.

    <div id="content">
    <div class="content-column">
      <?php 
        $cols = 3; // Change to columns needed.
        $catcount = count($categories);
        $catpercol = ceil($catcount / $cols);
        $c = 0;
        foreach ($categories as $category) { 
          if ( $c == $catpercol ) {
            $c = 0;
            print "</div><div class='content-column'>";
          }
     ?>
      <div class="manufacturer-list">
        <div class="manufacturer-heading"><?php echo $category['name']; ?><a id="<?php echo $category['name']; ?>"></a></div>
        <div class="manufacturer-content">
          <?php if ($category['manufacturer']) { ?>
          <?php for ($i = 0; $i < count($category['manufacturer']);) { ?>
          <ul>
            <?php $j = $i + ceil(count($category['manufacturer']) / 4); ?>
            <?php for (; $i < $j; $i++) { ?>
            <?php if (isset($category['manufacturer'][$i])) { ?>
            <li><a href="<?php echo $category['manufacturer'][$i]['href']; ?>"><?php echo $category['manufacturer'][$i]['name']; ?></a></li>
            <?php } ?>
            <?php } ?>
          </ul>
          <?php } ?>
          <?php } ?>
        </div>
      </div>
      <?php $c++; } ?>
    </div>
    </div>
    

    Add .content-column { float: left; width: 33.33333%; } to your CSS.

    Details:
    $cols = 3; enables you to set the desired number of columns (note: you might need to change CSS accordingly).

    $catcount = count($categories); gives you the total number of categories about to be rendered.

    $catpercol = ceil($catcount / $cols); divides that total number evenly into the required number of columns with the last column having eventually less items than the others.

    $c = 0; is your counter. It increases at the end of the outer foreach loop.

    Within the loop, $cis checked if it matches the $catpercol number and if so, the current parent div is closed and a new one created. You end up with as many parent divs as you need columns. Just add appropiate CSS to make them appear besides each other.

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

Sidebar

Related Questions

Note: This code actually codes from a tutorial book I'm reading at the moment,
I have a code at the moment that takes a line from a .txt
At the moment my code looks like this: # Assign values for saving to
I have this source code at the moment, but the issue I am having
At the moment I have this code which fires a projectile: Vector3 d =
I'm learning Ajax at the moment. The code below basically receives the echo from
I have this perl code below, basically want to loop through these 2 files.
I have a large data coming from a csv file which looks something like
I'm using the STL map data structure, and at the moment my code first
The following code summarizes the problem I have at the moment. My current execution

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.