Welcome Guest, Not a member yet? Register   Sign In
CI 2 foreach inside foreach in slideshow?
#1

[eluser]Alex Florea[/eluser]
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 in the slidshow and limit by number of row.

My model:
Code:
<?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();
}

}

My controler:
Code:
public function index()
{

$data['category_chaneels'] = $this->pages_model->get_channels_by_categ_tv();

$this->template->page_view($data);
}

My view:

Code:
<ul class="slides">
   <li>
      &lt;?php $cat_shown = ''; ?&gt;
         <div class="programe-tv_link">
                &lt;?php $cat_show = ''; $cnl_show = '';?&gt;
                &lt;?php foreach ($category_chaneels as $category): ?&gt;
                    &lt;?php
                    if ($cat_show != $category['category_name']) {
                        $cat_show = $category['category_name'];
                        echo '<p>' . $cat_show . '</p>';
                    }
                    $cnl_show = $category['channel_name'];
                    echo '<dd><a href=""> >>' . $cnl_show . '</a></dd> ';
                    ?&gt;    
                &lt;?php endforeach; ?&gt;  
          </div>
     </li>
     <li>
              <div class="programe-tv_link">
                    <p>Arte</p>
                   <dd> <a href="">>> Acasa</a></dd>
                   <dd> <a href="">>> Antena 1</a></dd>
                   <dd> <a href="">>> Pro TV</a></dd>
                </div>
                <div class="programe-tv_link">
                    <p>Music Box</p>
                   <dd> <a href="">>> Acasa</a></dd>
                   <dd> <a href="">>> Antena 1</a></dd>
                   <dd> <a href="">>> Pro TV</a></dd>
                   <dd> <a href="">>> TLC</a></dd>
                </div>
      </li>
  </ul>

I atache image with ilustration,
[Image: w6l7_J.jpg]




Theme © iAndrew 2016 - Forum software by © MyBB