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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:35:50+00:00 2026-05-29T15:35:50+00:00

i have MySql Table name ‘category’, in that table i have id catname parent_id

  • 0

i have MySql Table name ‘category’, in that table i have

id   catname   parent_id
1    animals
2    vegs        
3    dog        1
4    cat        1
5    carrot     2

i just wanna display this data in html nested ‘ul’ like

<ul>
  <li>Animals
      <ul>
         <li>dog</li>
         <li>cat</li>
      </ul>
  </li>
  <li>Vegs
     <ul>
         <li>Carrot</li>
      </ul>
 </li>
</ul>

with php, please help me to get this data with php(CodeIgniter) and display.

  • 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-29T15:35:51+00:00Added an answer on May 29, 2026 at 3:35 pm

    Here are the three components for your question: controller, model and view…

    <!-- THE VIEW -->
    
    <ul>
    <?php foreach($main_cat->result() as $rowm) : ?>
    
        <li><?php echo $rowm->catname ?>
            <ul>
            <?php
                $id = $rowm->id;
                $sec_cat = $this->yourmodel->get_secondary($id);
                foreach($sec_cat->result() as $rows) :
            ?>
    
                <li><?php echo $rows->catname ?></li>
    
            <?php endforeach; ?>
            </ul>
        </li>
    
    <?php endforeach; ?>
    </ul>
    
    
    
    <!-- THE CONTROLLER -->
    
    <?php
    
    class Welcome extends CI_Controller {   
       function index()
       {
          $data['main_cat'] = $this->yourmodel->get_main();
          $this->load->view('welcome_view',$data);
       }
    } 
    ?>
    
    
    
      <!-- THE MODEL -->
    
    <?php
    class Yourmodel extends CI_Model {
    
    function get_main()
    {
        $this->db->where('parent_id','');
        $query = $this->db->get('category');
        return $query;
    }
    
    function get_secondary($parent)
    {
        $this->db->where('parent_id',$parent);
        $query = $this->db->get('category');
        return $query;
    }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table that includes the fields: Name - Year - Description
I have a MySQL table that keeps details about people, for example: Name Address
I have a mysql table id,name,gender,age religion( enum('HIN','CHR','MUS') ,category(enum('IND','AMR','SPA') where last 2 are enum
I have a MySQL table that looks like this: id (int primary) name (text)
I have mysql table with collumns like 'operation.date', 'operation.name' and etc. After fetching that
I have one MYSQL table. In that table there is one column name SRNO
I have a MySQL table that looks like this: Table: Designer id: integer name:
Suppose i have a mysql table name table with fields rank date id The
i have such mysql db table: id name surname number 1 emil asadi 26
I have a MySQL table structured somewhat like this: type name value ===================== 1

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.