[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>
<?php $cat_shown = ''; ?>
<div class="programe-tv_link">
<?php $cat_show = ''; $cnl_show = '';?>
<?php foreach ($category_chaneels as $category): ?>
<?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> ';
?>
<?php endforeach; ?>
</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,