Error Help

Hello frens, i am currently working on a project and i got an error. I tried to troubleshoot but couldn’t do it. I have highlighted the error in red.
i am using codeigniter as a framework.
The error says:
A PHP Error was encountered

Severity: Notice

Message: Object of class stdClass could not be converted to int

Filename: views/news.php

Line Number: 189

<div class="span4 custom">
                    <div class="divHeader">
                        News Archive (2013)
                    </div>           
                                            
                    <dl>
                        <?php
                            $currentMonth = date('m');    
                            for ($c = $currentMonth; $c >= 1; $c--){                            
                                $all['month'.$c] = $this->news_model->get_by_month($c);
                            ?>
                                <dt><?php 
                                    $monthName = date("F", mktime(0, 0, 0, $c, 10));
                                    echo $monthName;
                                    ?>
                                </dt>
                                <dd>
                                    <ul>                           
                                
                            <?php                        
                                foreach ($all['month'.$c] as $values){
                            ?>          
                                                                          
                                        <li>
                                          <?php if(count($values > 0)){ ?>
                                            <a href="<?php echo base_url() . 'news/news_detail/' . $values->new_id; ?>"><?php echo $values->new_title; ?></a>
                                            <?php }else{ ?>
                                            No data
                                             <?php } ?>
                                        </li>
                                        
                                                                                                 
                                       
                                
                            <?php
                                }//foreach statement ends
                            ?>
                                   </ul>
                                </dd>
                                  
                            <?php 
                            }//for statements ends
                        ?>                        
                    </dl>                 


                   
                </div><!-- span 3-->

Change

 if(count($values > 0))

in

 if(count($values) > 0)

I tried but its saying the same error. Nyway thanks :slight_smile:

If you’re sure that the error is in the red line, do a var_dump($values); just before that if and see what’s in $values

Another thought, where is “$this->news_model->get_by_month($c)” getting its data from?

Does it have a length property on its return type?

So that

<?php if(count($values > 0)){ ?>

Becomes

<?php if($values->length > 0){ ?>

I also agree with Guido, that you need to produce a var_dump of $values to see what this value actually is.

Yes, finally debugged it. thank you guys for your concern. it helped a lot.

  <div class="span4 custom">

                    <?php
                        $currentYear = date('Y');
                        $this->db->select_min('YEAR(new_publish_date)','min_year');                        
                        $this->db->from('news')                 ;
                        $query = $this->db->get();
                        $result = $query->result();                        
                        foreach ($result as $year) {
                            $min_year = $year->min_year;
                        }//foreach ends
                        $j=$currentYear;
                        for ($i=$currentYear; $i >= $min_year; $i--) { 
                    ?>
                        <div class="divHeader">
                            News Archive (<?php echo $i; ?>)
                        </div>                                           
                        <dl>
                        <?php if($i == $j){ 
                                    $currentMonth = date('m');    
                                    for ($c = $currentMonth; $c >= 1; $c--){                            
                                        $all['month'.$c] = $this->news_model->get_by_month($c, $i);
                                        $all['rowsCount'.$c] = $this->news_model->get_by_month_RowCount($c, $i);
                                    ?>
                                        <dt><?php 
                                            $monthName = date("F", mktime(0, 0, 0, $c, 10));
                                            echo $monthName;
                                            ?>
                                        </dt>
                                        <dd>
                                            <ul>                           
                                        
                                    <?php
                                        if($all['rowsCount'.$c] > 0){                               
                                            foreach ($all['month'.$c] as $values){
                                    ?>                                                           
                                                <li>                                           
                                                    <a href="#"><?php echo !empty($values->new_title) ?  $values->new_title:"No data" ;?></a>                                            
                                                </li>                                      
                                    <?php
                                            }//foreach statement ends
                                        }else{
                                    ?>
                                            <li>                                           
                                                Sorry No Data found
                                            </li>
                                    <?php
                                        }
                                    ?>
                                           </ul>
                                        </dd>
                                          
                                    <?php 
                                    }//for statements ends
                     
                         }else{ ?>

                             <?php 
                                    $currentMonth = 12;    
                                    for ($c = $currentMonth; $c >= 1; $c--){                            
                                        $all['month'.$c] = $this->news_model->get_by_month($c, $i);
                                        $all['rowsCount'.$c] = $this->news_model->get_by_month_RowCount($c, $i);
                                    ?>
                                        <dt><?php 
                                            $monthName = date("F", mktime(0, 0, 0, $c, 10));
                                            echo $monthName;
                                            ?>
                                        </dt>
                                        <dd>
                                            <ul>                           
                                        
                                    <?php
                                        if($all['rowsCount'.$c] > 0){                               
                                            foreach ($all['month'.$c] as $values){
                                    ?> 
                                                <li>                                           
                                                    <a href="#"><?php echo !empty($values->new_title) ?  $values->new_title:"No data" ;?></a>                                            
                                                </li>                      
                                        
                                    <?php
                                            }//foreach statement ends
                                        }else{
                                    ?>
                                            <li>                                           
                                                Sorry No Data found
                                            </li>
                                    <?php
                                        }
                                    ?>
                                           </ul>
                                        </dd>
                                          
                                    <?php 
                                    }//for statements ends
                                ?>
                        <?php
                        } ?>                        
                        </dl>        
                                                  
                    <?php
                    }
                    ?>                                
                </div><!-- span 3-->