[eluser]RobertB.[/eluser]
Hello,
I'm having a problem showing only one of my fields
(active) in the view.
MODEL
Code:
function getCategories()
{
$this->db->select('c.id, c.category, COUNT(sb.bus_id) AS active, c.permalink, sc.cat_id');
$this->db->from('categories c');
$this->db->join('subcats sc', 'c.id = sc.cat_id', 'left');
$this->db->join('subcat2bus sb', 'sc.id = sb.subcat_id', 'left');
$this->db->join('businesses b', 'sb.bus_id = b.id', 'left');
$this->db->group_by('c.id');
$this->db->order_by('c.category', 'asc');
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
}
CONTROLLER
Code:
function index()
{
$this->categories();
}
function categories()
{
$data['categories'] = $this->listings->getCategories();
//print_r($data['categories']);
//die();
$data['main_content'] = 'listings/categories_view';
$this->load->view('templates/template', $data);
}
VIEW
Code:
<?php
$span_count = 1;
foreach($categories as $row => $category):
$span_style = ($span_count % 2) ? 'span-12' : 'span-12 last';
?>
<div class="<?=$span_style?>">
<?php
$class = ( ! $category->active > 0) ? 'categories empty' : 'categories';
$active = ' <small>['.$category->active.']</small>';
$inactive = ' <small>[0]</small>';
?>
<ul class="<?=$class?>" id="category">
<li><?php if($category->active > 0) { ?>
<?=anchor('category/'.$category->permalink, $category->category) .$active?>
<?php } else { ?>
<?=$category->category.$inactive?>
<?php }; ?>
</li>
</ul>
</div>
<?php $span_count++; endforeach; ?>
If I print_r($data['categories']) I can see it there with the count but for some reason does not display in the view
Part of
print_r($data['categories'])
Code:
Array ( [0] => stdClass Object ( [id] => 2 [category] => Arts & Entertainment [active] => 13 [permalink] => arts-entertainment [cat_id] => 2 ) [1] => stdClass Object ( [id] => 3 [category] => Attorneys & Legal Services [active] => 0 [permalink] => attorneys-legal-services [cat_id] => 3 )
It was working before I made some changes and one of the changes were I change the database engine to MyISAM I hope this have nothing todo with it.
Thanks.