Welcome Guest, Not a member yet? Register   Sign In
MySQL Search - Resolved
#1

[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();
    }


Messages In This Thread
MySQL Search - Resolved - by El Forum - 10-21-2009, 12:51 PM
MySQL Search - Resolved - by El Forum - 10-21-2009, 01:03 PM
MySQL Search - Resolved - by El Forum - 10-21-2009, 01:10 PM
MySQL Search - Resolved - by El Forum - 10-21-2009, 01:53 PM
MySQL Search - Resolved - by El Forum - 10-21-2009, 03:34 PM
MySQL Search - Resolved - by El Forum - 02-26-2010, 01:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB