SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Error Help

  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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


    PHP Code:
    <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(000$c10));
                                        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-->
    Last edited by cpradio; Oct 7, 2013 at 08:10. Reason: removed useless localhost link

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Change
    PHP Code:
     if(count($values 0)) 
    in
    PHP Code:
     if(count($values) > 0

  3. #3
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried but its saying the same error. Nyway thanks

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    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

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,136
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?php if(count($values 0)){ ?>
    Becomes
    PHP Code:
    <?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.

  6. #6
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, finally debugged it. thank you guys for your concern. it helped a lot.
    PHP Code:
      <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(000$c10));
                                                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(000$c10));
                                                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-->


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •