Welcome Guest, Not a member yet? Register   Sign In
Issue with joining tables.
#1

(This post was last modified: 08-24-2018, 03:13 PM by HarrysR. Edit Reason: Added the 404 issue too.. )

Hey guys,
I know it might be a silly question but i can't make it work and it drives me crazy.

I have a view.php for displaying single item details. In model file i'm trying to join some tables (in which some columns are INT and have 0 value).

When I'm trying to get a single entry where the INT column is 0, i can't get any info shown in the "view.php" file (if i also place the show_404 if data are empty i get redirected. Which means that it does not get any data).
When i erase the db join it works fine. My guess is something i made wrong with the db or the model.

Any ideas?!
Controller
Code:
 public function view($pet_entry_id = NULL, $pet_entry_slug = NULL){
   //Data
   $data['pet'] = $this->pet_model->get_pets($pet_entry_id);
   $data['images'] = $this->pet_model->get_images($pet_entry_id);

   //Same page redir with entry-id given
   if (!$pet_entry_slug) {
     redirect(site_url('pets/' . $data['pet']['pet_entry_id'] . '/' . $data['pet']['pet_entry_slug']), 301);
   }

   if( empty($data['pet']) ){
     redirect('pets');
   }

   //Meta data
   $seo_data['title'] = $data['pet']['pet_entry_title'] . ' - Petgee.gr';
   $seo_data['meta_descr'] = $data['pet']['meta_descr'];
   $seo_data['meta_keywords'] = $data['pet']['meta_keywords'];

   // View files
   $this->load->view('templates/header', $seo_data);
   $this->load->view('pets/view', $data);
   $this->load->view('templates/footer');
 }



Model file
Code:
 public function get_pets($pet_entry_id = 0, $pet_entry_slug = FALSE){
   $this->db->join('users', 'users.user_id = pets.pet_user_id');
   $this->db->join('pet_categories', 'pet_categories.pet_category_id = pets.category_id');
   $this->db->join('pet_breeds', 'pet_breeds.pet_breed_id = pets.pet_breed');

   if($pet_entry_id === 0 && $pet_entry_slug === FALSE ){
     $this->db->order_by('pet_id', 'DESC');

     $query = $this->db->get('pets');
     return $query->result_array();
   }

   $query = $this->db->get_where('pets', array('pet_entry_id' => $pet_entry_id, 'pet_entry_slug' => $pet_entry_slug));
   return $query->row_array();
 } //Get pets (end)



Thank you in advance!

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


Messages In This Thread
Issue with joining tables. - by HarrysR - 08-24-2018, 03:11 PM
RE: Issue with joining tables. - by jreklund - 08-25-2018, 05:31 AM
RE: Issue with joining tables. - by HarrysR - 08-25-2018, 12:33 PM
RE: Issue with joining tables. - by HarrysR - 08-25-2018, 02:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB