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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:43:56+00:00 2026-05-13T18:43:56+00:00

The MySQL query: SELECT title,alias,parent FROM ‘._prefix.’categories WHERE (language = \”._language.’\’ || language =

  • 0

The MySQL query:

SELECT title,alias,parent FROM '._prefix.'categories 
WHERE (language = \''._language.'\' || language = \'all\') 
&& status = \'published\'
ORDER BY rank ASC

The Result (from phpMyAdmin):

title    |  alias   |  parent
Home     | home     |    0
Todo     | todo     |    0
Multiuser| todo_mu  |    21
Modulsys | todo_mod |    21

The PHP:

while($c = mysql_fetch_array($category_result)) {
    if($c['parent'] == 0) {
        $output .= '<li><a href="'._rewrite_string.$c['alias'].'" title="'.$c['title'].'">'.$c['title'].'</a>';

        $output .= '<ul>';

        mysql_data_seek($category_result,0);

        while($d = mysql_fetch_array($category_result)) {

            $output .= '<li class="space_left"><a href="'._rewrite_string.$c['alias'].'/'.$d['alias'].'" title="'.$d['title'].'">'.$d['title'].'</a>';

            $output .= '</li>';

        }

        $output .= '</ul>';

        $output .= '</li>';
    }
}

This should generate a category list like that

cat 1

  • subcat 1
  • subcat 2

cat 2

cat 3

but it generates something like that

cat 1

  • cat 1
  • cat 2
  • subcat 1
  • subcat 2

using the mysql_fetch_array into another (nested) without using mysql_data_seek
causes an abort once the nested mysql_fetch_array was called. it only outputs cat1 and nothing more.

please provide me the solution, thank you

  • 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-13T18:43:57+00:00Added an answer on May 13, 2026 at 6:43 pm
    $i = 0;
    while($c = mysql_fetch_array($category_result)) {
        $parent = $c['parent'];
        $next_row = $i + 1;
    
        $not_last_row = (mysql_data_seek($category_result, $next_row)); //Move ahead to get next parent or returns false if on last row...
        $next_parent = (!$not_last_row) ? $c['parent'] : FALSE;
        mysql_data_seek($category_result, $i); //Move back to current row
    
        $open_list = ($parent != $prev_parent);
        $close_list = (($parent > $next_parent) || !$not_last_row); //close list if next parent is smaller number or if this is last row.
    
        $output .= ($open_list) ? "<ul>" : "";
    
        $output .= '<li>'.$c['title'].'</li>';
    
        $output .= ($close_list) ? '</ul>' : "";
    
        $prev_parent = $parent; //Set this so that on next loop, we can see if they match
        $i++;
    }
    

    It’s a bit rushed, but I think this is what you have in mind. Basically, if the previous parent does not match the current parent, open a list. If the current parent is greater than the next parent, close the list.

    You will probably need to add something to account for it being the last iteration.

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

Sidebar

Ask A Question

Stats

  • Questions 352k
  • Answers 352k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First explode() the array with the delimiter * You could… May 14, 2026 at 7:30 am
  • Editorial Team
    Editorial Team added an answer All of the base GWT Widgets are cross-browser compatible -… May 14, 2026 at 7:30 am
  • Editorial Team
    Editorial Team added an answer I haven't used it but there is an mvcsitemap project… May 14, 2026 at 7:30 am

Related Questions

I am working on my website, and I am trying to get the url
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM
I have a MySQL database where users can list books they've read, want to
I'm trying to call a function from a form within the same .php file,
HI, I have code like this. what I am doing is populating the first

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.