Welcome Guest, Not a member yet? Register   Sign In
Problem with the view
#1

[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="&lt;?=$span_style?&gt;">
                
                &lt;?php
                    
                    $class = ( ! $category->active > 0) ? 'categories empty' : 'categories';            
                    $active = ' <small>['.$category->active.']</small>';
                    $inactive = ' <small>[0]</small>';
                    
                ?&gt;
                    
                    <ul class="&lt;?=$class?&gt;" id="category">
                        <li>&lt;?php if($category->active > 0) { ?&gt;
                              &lt;?=anchor('category/'.$category->permalink, $category->category) .$active?&gt;
                                &lt;?php } else { ?&gt;
                                &lt;?=$category->category.$inactive?&gt;
                            &lt;?php }; ?&gt;
                        </li>
                    </ul>
                        
            </div>
            
        &lt;?php $span_count++; endforeach; ?&gt;

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.
#2

[eluser]n0xie[/eluser]
What does this output:
Code:
<ul class="&lt;?=$class?&gt;" id="category">
&lt;?php echo $category->active; ?&gt;
                        <li>&lt;?php if($category->active > 0) { ?&gt;
#3

[eluser]RobertB.[/eluser]
Code:
&lt;?=$category->active?&gt;

The ones that have records in it returns 0 and the ones that does not nothing.
Is very strange because it is returning a count in the print_r.

Is not passing from the controller to the view.
#4

[eluser]RobertB.[/eluser]
If I print_r($categories) in the view this is what I get
Code:
Array ( [0] => stdClass Object ( [id] => 2 [category] => Arts & Entertainment [active] => 0 [permalink] => arts-entertainment [cat_id] => 2 ) [1] => stdClass Object ( [id] => 3 [category] => Attorneys & Legal Services [active] => [permalink] => attorneys-legal-services [cat_id] => 3)
#5

[eluser]RobertB.[/eluser]
I don't know why yet but I've disable some jquery that I had on the view and it is working now. I will update this ASAP

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB