I have a category table that names each category, then I have an artwork table that has three columns offering three different categories per art piece. I am building a select query that will look in all three columns of one category and join the category table so I can get the category name. I have alias' for each join, but my query is still returning null values for category_id2 and category_id3. Any assistance is greatly appreciated.
From Codeigniter Model:
function category_search($category) {
$this -> db -> select('a.id, a.artist_fname, a.artist_lname, b.artist_id, b.sm_file_name, b.category_id, b.category_id2, b.category_id3, c.id, c.category');
$this -> db -> from('ap_mini_artist a', 'ap_mini_artwork b', 'ap_art_categories c', 'ap_art_categories c2', 'ap_art_categories c3');
$this -> db -> where('c.category', $category, 'after');
$this -> db -> join('ap_mini_artwork b', 'b.artist_id=a.id', 'left');
$this -> db -> join('ap_art_categories c', 'c.id=b.category_id', 'left');
$this -> db -> join('ap_art_categories c2', 'c2.id=b.category_id2', 'left');
$this -> db -> join('ap_art_categories c3', 'c3.id=b.category_id3', 'left');
$query = $this -> db -> get();
return $query -> result();
}
From Controller if needed:
public function category_search() {
$category = $this -> input -> post('categoryValue');
$query = $this -> mini_show_model -> category_search($category);
if (!empty($query)) {
$json = json_encode($query);
print $json;
} else {
echo "Your query is empty, please try again.";
}
}
Thanks for your help!