Welcome Guest, Not a member yet? Register   Sign In
Undefined Property...stdClass. Cant figure it out
#1

[eluser]jk215[/eluser]
Ive been staring at this all morning and I cant figure out why its not working. $entry->listing_url works but $entry->listing_title doesnt. Any help is appreciated.

Here is the error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$listing_title
Filename: listings/index.php
Line Number: 5

Here is my controller:
Code:
<?php

class Listings extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
    }
    
    // homepage showing all listings
    public function index() {
        $this->load->model('Listings_model', 'listings');
        $entries['query'] = $this->listings->get_all_entries();
        
        $this->load->view('header');
        $this->load->view('listings/index', $entries);
        $this->load->view('footer');
    }
}

Here is my model:
Code:
<?php

class Listings_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
    }

    //Gets all entries in listings table
    public function get_all_entries()
    {
        $this->db->select('listing_url', 'listing_title');
        $query = $this->db->get('listings');
        
        if ($query->num_rows() > 0)
        {
            return $query->result();
        }
        else
        {
            return array();
        }
    }

}

Here is my view:
Code:
<?php foreach ($query as $entry) { ?>
  <div class="blog_entry">
    <h2><a >listing_url; ?&gt;">&lt;?php echo $entry->listing_title; ?&gt;</a></h2>
    <span class="metadata">meta</span>
  </div>
  &lt;?php } ?&gt;
#2

[eluser]jk215[/eluser]
that view came out weird. the anchor tag leads up to $entry->listing_url;
#3

[eluser]bubbafoley[/eluser]
in get_all_entries() you are only selecting listing_url.

do it like this
Code:
$this->db->select('listing_url, listing_title');
#4

[eluser]jk215[/eluser]
Wow I NEVER would have seen that. I was inputting values in mysql all day got single quote happy. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB