php - A Database Error Occurred Error Number: 1064 -
i've been working on project , wan't trying figure out how make union
mysql method in codeigniter 3, can't find problem have, here's model file i've created, can 1 help:
class reference_model extends ci_model { function search($term,$orig){ //affichage des produits par référence $this->db->select('*') ->distinct() ->from('treference') ->like('sreference',$term) ->or_like('nreference', $term) ->or_like('ssearch', $term) ->or_like('ssort', $term) ->get(); $q1 = $this->db->last_query(); if (isset($orig)) { $this->db->select('nmanufacturer') ->distinct() ->from('tmanufacturer') ->where_in('nmanufacturer=treference.nmanufacturer') ->get(); $q2 = $this->db->last_query(); }else { $q2=''; } $query = $this->db->query($q1." union ".$q2); $ret = array(); $ret['rows'] = $query->result(); $ret['number'] = $query->num_rows(); return $ret; } }
and thank help
if trying union
of 2 query there requirements names of columns (which being selected) should same..
in case , in 1st query select('*')
, in 2nd select('nmanufacturer')
, sure, these 2 queries selecting different columns.
Comments
Post a Comment