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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:18:53+00:00 2026-06-06T23:18:53+00:00

I have built the following function, but is it possible to get it to

  • 0

I have built the following function, but is it possible to get it to split my lists from one into more so I can have a maximum of 8 <li>‘s per <ul>?

function buildProductsMenu($base) {

    $sql = "SELECT *
            FROM tbl_category";
    $result     = dbQuery($sql);
    while ($row = dbFetchAssoc($result)) {
    echo "<ul>";        
        echo "<li class='title'>$row[cat_name]</li>";
            $sqlProd = "SELECT *
                FROM tbl_product WHERE cat_id = $row[cat_id]";
            $resultProd     = dbQuery($sqlProd);
            while ($rowProd = dbFetchAssoc($resultProd)) {
                extract($rowProd);
                echo "<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
            }       
    echo "</ul>";               
    }
}

Went with jurgemaister Solution

function buildProductsMenu($base) {

    $sql = "SELECT *
            FROM tbl_category";
    $result     = dbQuery($sql);
    while ($row = dbFetchAssoc($result)) {
        echo "<ul>";        
        echo "<li class='title'>$row[cat_name]</li>";
        $sqlProd = "SELECT * FROM tbl_product WHERE cat_id = $row[cat_id]";
        $resultProd     = dbQuery($sqlProd);
        $counter = 1;
        while ($rowProd = dbFetchAssoc($resultProd)) {
            extract($rowProd);
            if($counter % 12 == 0) {
                $counter = 1;
                echo "</ul><ul style='margin-top:25px;'>";
            }
            echo "<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
            $counter++;
        }
        echo "</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-06T23:18:54+00:00Added an answer on June 6, 2026 at 11:18 pm

    You can add a counter, and when that counter reaches 8, you start a new ul.

    $counter = 1;
    while ($rowProd = dbFetchAssoc($resultProd)) {
        extract($rowProd);
    
        if($counter % 8 == 0) {
            $counter = 1;
            echo "</ul><ul>";
        }
    
        echo "<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
        counter++;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I have following problem: I have built a tabbar application with 4 tabs. I
How do I do the following using built-in modules only? I have a list
I've built a dialogbox with a RichTextBox and I'd like to have the following
I have to build a tree using the following data which comes from a
Is it possible to have multiple specializations of a variadic template where one of
I have the following function in my c# silverlight application to find the total
I'm trying to use hibernates built in createsql function but it seems that it
I saw the following function in a posting which allows one to order data
I have the following situation: void function(params) { #ifdef _MULTIPLAYER if (isConnected) { if

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.