[eluser]georgerobbo[/eluser]
I am starting to develop a search form, however I need to search two different tables with the same query.
The two tables I wish to query are post, and tag. You can guess what the tag table does. The post table contains all the uploads/posts.
Post
Quote: `ID` int(11) NOT NULL auto_increment,
`title` varchar(25) NOT NULL,
`permalink` varchar(50) NOT NULL,
`author` varchar(25) NOT NULL,
`username` varchar(25) NOT NULL,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
`filename` varchar(25) NOT NULL,
`description` varchar(200) NOT NULL,
`category` varchar(25) NOT NULL,
`comments` int(11) NOT NULL,
`favourites` int(11) NOT NULL,
`views` int(11) NOT NULL,
PRIMARY KEY (`ID`)
ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Tag
Quote: `ID` int(11) NOT NULL auto_increment,
`post` int(11) NOT NULL,
`tag` varchar(20) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
I want to select results from the two tables based on the one keyword. However I do not know how to do this in my model function.
Code:
function search($query)
{
$this->db->select('*');
$this->db->where('title', $query);
$this->db->or_where('author', $query);
$this->db->or_where('description', $query);
$this->db->or_where('category', $query);
// How do I select a row from another table within the function?
$query = $this->db->get('post'); // How do I search both post and tag?
return $query->result_array();
}