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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:11:51+00:00 2026-06-18T01:11:51+00:00

In codeigniter 2.1 I’m trying to display channels by category. So if i have

  • 0

In codeigniter 2.1 I’m trying to display channels by category. So if i have a category called Film, i should see a list of Channels within Film. I tried a nested foreach loop to accomplish this but can’t seem to get it to work.

My tables structure is something like this but more complicated:

Database structure

  • My model:

    <?php
    
    class Pages_model extends CI_Model {
    
    
    function get_channels_by_categ_tv()
    {
    
      $this->db->select('categories.category_name, channels.channel_name');
      $this->db->from('type_categ');
      $this->db->join('categories', 'categories.category_id = type_categ.category_id');
      $this->db->join('channels', 'channels.channel_id = type_categ.channel_id');
      $this->db->order_by('categories.category_id');
    //$this->db->group_by(array('categories.category_id')); 
      $query = $this->db->get();
    
      if($query->num_rows() == 0)
      {
        #no channels
        return false;
      }
    
      return $query->result_array();
    }
    
    }
    
  • in the view:

              <ul class="slides">
                <li>
                    <?php foreach ($category_chaneels as $category): ?>
                    <div class="programe-tv_link">
                        <p><?=$category['category_name'];?></p>
                           <dd> <a href=""> >> <?=$category['channel_name'];?></a></dd>
                    </div>
                    <?php endforeach; ?>                  
                </li>
              </ul>
    
  • controller (Pages):

    public function index()
    {
    
    $data['category_chaneels'] = $this->pages_model->get_channels_by_categ_tv();
    
    $this->template->page_view($data);
    }
    

I atached image 1 and image 2, i need result like image 2 not 1.

PS. One channel can have many categories.

enter image description here
Can you help me ? THX

  • 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-18T01:11:52+00:00Added an answer on June 18, 2026 at 1:11 am

    My final code is this. Maby sombody need this.

        <div id="programe-tv-slide" class="flexslider">
            <strong>Programe TV</strong>
            <div class="redLine"></div>
    
            <?php $cat_cnl = array(); 
                  $list = array(); 
                  $i=1;
                     foreach ($category_chaneels as $option) { 
                        $catname = $option['category_name'];
                        $chlname = $option['channel_name'];
    
                        $cat_cnl[$catname][$i] = $chlname;
                        $list[$i] = $catname;
                  $i++;
                     }; 
            ?>
            <?php 
                $rows = array_chunk($cat_cnl, 4, TRUE);
                foreach ($rows as $row) {  //var_dump($rows);
            ?>
    
              <ul class="slides">    
                <?php
                    echo ('<li>');
                    foreach ($row as $category => $channels) {
                        echo '<div class="programe-tv_link">'; 
                        echo '<p>' . $category . '</p>'; 
                            foreach ($channels as $channel) {
                                    echo '<dd><a href="">' . $channel . '</a></dd> '; 
                            };
                        echo '</div>'; 
                        };      
                    echo ('</li>'); 
                ?>
              </ul>
              <?php }; ?>
        </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In codeigniter 1.73 i'm trying to display books by category. so if i have
Does Codeigniter 2 have a cleaner way of doing what's shown in the code,
In CodeIgniter I would do: print_r ($this->db->queries); In Yii I tried: print_r (Yii::app()->db) But
In CodeIgniter I'm using a base CRUD My_model , but I have this small
Using CodeIgniter, how do I access and display text entered into an input field
Using CodeIgniter, I am trying to place several images onto my view page as
CodeIgniter - I have a public function in a controller but I don't want
Using codeigniter 2.1.2, I have a form view loaded through a controller that takes
I'm using CodeIgniter (v1.7.2) and I've created a custom controller that incorporates authentication called
I am using codeigniter php MVC framework to develop a web application. I have

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.