Welcome Guest, Not a member yet? Register   Sign In
Similar entries function.
#1

I'm trying to create a "similar entries" function in codeigniter but the code so far gets me an error..

Controller 
Code:
$data['similar'] = $this->pet_model->get_similar($pet_entry_id);


Model
Code:
 public function get_similar($pet_entry_id){
   $this->db->select('category_id');
   $this->db->from('pets');
   $this->db->where('pet_entry_id', $pet_entry_id);
   $pet_type = $this->db->get();

   $this->db->select('pet_status');
   $this->db->from('pets');
   $this->db->where('pet_entry_id', $pet_entry_id);
   $pet_status = $this->db->get();

   $query = $this->db->get_where('pets', array('category_id' => $pet_type, 'pet_status' => $pet_status) );
   return $query->result_array();
 }

The php error shows that these values are blank:
Code:
SELECT * FROM `pets` WHERE `category_id` = AND `pet_status` =


I think that the issues comes from the queries... But where..?!?! Tongue

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply
#2

$this->db->get() does not return a field value from your table, but just a database object.
To get the value of the field:
PHP Code:
$pet_type $this->db->get()->row()->pet_type;
$pet_status $this->db->get()->row()->pet_status
Reply
#3

(09-06-2018, 07:58 AM)Wouter60 Wrote: $this->db->get() does not return a field value from your table, but just a database object.
To get the value of the field:
PHP Code:
$pet_type $this->db->get()->row()->pet_type;
$pet_status $this->db->get()->row()->pet_status

I think it works fine! Thank you!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB