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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:37:43+00:00 2026-06-12T06:37:43+00:00

I am trying to place a limit clause on the database query to only

  • 0

I am trying to place a limit clause on the database query to only show the first 4 results.

The current code I am working with is

    $categories_query = "select c.categories_id, cd.categories_name, c.parent_id
                      from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd 
                       where c.categories_id = cd.categories_id
                       and c.categories_status=1 " .
//                             "and c.categories_id = ptc.category_id " .
//                             "and ptc.category_id = cd.categories_id " .
//                             "and ptc.product_type_id not in  " . $this->document_types_list . "
                       " and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                         order by c.parent_id, c.sort_order, cd.categories_name";
         $categories = $db->Execute($categories_query);
         while (!$categories->EOF) {
           $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
           $categories->MoveNext();
         }

The problem that I am having is I found a way to limit only 4 results by placing LIMIT 4 after the order query, and it shows the first 4 parent categories, but it also removes the sub categories from the list.

So I want to take this

<ul>
   <li>Menu One</li>
   <li>Menu Two
      <ul>
         <li>Submenu One</li>
         <li>Submenu Two</li>
         <li>Submenu Three</li>
      </ul>
   </li>
   <li>Menu Three</li>
   <li>Menu Four</li>
   <li>Menu Five</li>
   <li>ect...</li>
</ul>

and see this

<ul>
   <li>Menu One</li>
   <li>Menu Two
      <ul>
         <li>Submenu One</li>
         <li>Submenu Two</li>
         <li>Submenu Three</li>
      </ul>
   </li>
   <li>Menu Three</li>
   <li>Menu Four</li>
</ul>

and when placing ‘LIMIT 4’ in the query it only shows this

<ul>
   <li>Menu One</li>
   <li>Menu Two</li>
   <li>Menu Three</li>
   <li>Menu Four</li>
</ul>

How do I keep the subcategories with the parent categories? Aparently calling only the first 4 does not call the categories under it

  • 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-12T06:37:44+00:00Added an answer on June 12, 2026 at 6:37 am

    The query is doing exactly what you’re asking it to do – “LIMIT” means you get just 4 records back, ordered by categoryID.

    To get what you want, you have to rephrase the query – I haven’t go SQL installed on this laptop, so it’s hard to test, but something like this:

    $categories_query = "select c.categories_id, cd.categories_name, c.parent_id
                          from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd 
                           where c.categories_id = cd.categories_id
                           and c.categories_status=1 " .
                           " and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           " and c.parent_id in " .
                           " ( select parent_id from " . TABLE_CATEGORIES . " limit 4) " .
                           "  order by c.parent_id, c.sort_order, cd.categories_name";
             $categories = $db->Execute($categories_query);
             while (!$categories->EOF) {
               $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
               $categories->MoveNext();
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to place a nice border around an image that's 250x250, using only
I was trying to display a number of results but the code I have
I'm trying to place a flash video (object, swf) inside a div, and have
I'm trying to place a textbox into Fancybox2. However, when I click the textbox
I'm trying to place a button. I have its position set to absolute, so
I am trying to place a hyperlink in one of my NSIS pages. My
I'm trying to place a JComboBox inside a certain column of a JTable. I
I am trying to place a value (from an object) in a variable and
I am trying to place API variables on ONE class file or mxml file
I was trying to place some simple effects on an image using HBox using

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.