I have code like this:
function search_keyword(){
        $keyword = trim($_POST['keyword']);
        $search_explode = explode(" ", $keyword);
        $x = 0;
        $sql = " ( SELECT name AS type FROM global_info WHERE ";
        foreach($search_explode as $each){
            $x++;
            if($x == 1){
               $sql .= " name LIKE '%$each%'";}                          
            else {
                $sql .= " name LIKE '%$each%' ";
            }
        }
          $sql .= " ) UNION ALL "; 
          $sql .= " ( SELECT name AS type FROM person WHERE ";
        foreach($search_explode as $each){
            $x++;
            if($x == 1){
               $sql .= " name LIKE '%$each%'";}                          
            else {
                $sql .= " name LIKE '%$each%' ";
            }
        }
          $sql .= " ) UNION ALL ";
          $sql .= "( SELECT name AS type FROM event WHERE ";
        foreach($search_explode as $each){
            $x++;
            if($x == 1){
               $sql .= " name LIKE '%$each%'";}                          
            else {
                $sql .= " name LIKE '%$each%' ";
            }
        }
        $sql .= " ) ";
        $q = $this->db->query($sql);
         return $q = $q->num_rows() == 0 ? FALSE :  $q->result();
    }
The function is working. What I don't know is how to know which data is from which table, and then to show the results on the page?
 
     
    