Error:In displaying the contents from the databse on to the webpage (CMS site)

Error:In displaying the contents from the databse on to the webpage (CMS site)

我在一个 CMS 网站上工作,我遇到了一个问题,我试图从星期六开始修复它,但我不知道为什么会出现这样的错误。我收到这样的错误

Error: A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/services.php

这里我使用了两个值,一个是 results,另一个是 results,但我仍然不明白为什么它显示错误,因为 Trying to get 属性 of non -目的。此外,我在另一个页面中使用了相同的概念,它工作正常,但我不知道为什么我会在这里遇到这样的错误。请任何人都可以指导我。

这是我的Home.php(控制器)

    //-----------Services page-------------

        public function services()  
        {  
            $this->load->helper('url');
            $this->load->view('header');
            $data['results'] = $this->Contact_model->service_us_getvalue();
            $data['resultss'] = $this->Contact_model->service_us_getvalue1();
            $this->load->view('services',$data); 
            $this->load->view('footer');                    
        }

这是我的Contact_model.php

    //--------Service----------


    //query to select the different rows
    function service_us_getvalue()
    {
        return  $this->db->get('service_us')->row();
    }

    function service_us_getvalue1()
    {
        return  $this->db->get("service_us WHERE type='Section_2'")->result();
    }

Service.php

    //   This is how it looks when the website is in static mode this one I'm trying to convert dynamic.  

    <div class="col-md-6">
    <div class="media">
      <ul>
        <li>
          <div class="media-left">
            <i class="fa fa-pencil"></i>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Web Development</h4>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus interdum erat libero, pulvinar tincidunt leo consectetur eget.</p>
          </div>
        </li>
        <li>
          <div class="media-left">
            <i class="fa fa-book"></i>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Responsive Design</h4>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus interdum erat libero, pulvinar tincidunt leo consectetur eget.</p>
          </div>
        </li>
        <li>
          <div class="media-left">
            <i class="fa fa-rocket"></i>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Bootstrap Themes</h4>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus interdum erat libero, pulvinar tincidunt leo consectetur eget.</p>
          </div>
        </li>
      </ul>
    </div>
  </div>-->

    <?php
        if (isset($resultss))
        {
            echo $resultss->description; 
        }
    ?>

希望对您有所帮助:

service_us_getvalue1方法中使用row()代替result()

你的模型方法service_us_getvalue1应该是这样的:

function service_us_getvalue1()
{
  $this->db->where('type' , 'Section_2');
  return  $this->db->get("service_us")->row();
}

试试这个可能对你有帮助

<?php
        if (isset($resultss))
        {
            echo $resultss['description']; 
        }
    ?>