timmah1 Posted March 29, 2009 Share Posted March 29, 2009 I have a database for posts, and a database for users1 When you login, I need to grab everything from the posts database that matches your userid, and grab everything from the users1 database that matches the followers id. Meaning, the users1 database has two fields (userid, followers) So, if my userid is 4, I need to check the users1 database for that userid, if there is one, then I need to grab the followers table input and pull the info from the posts database with the followers number as well as mine. Does this make sense? I'm trying a join, but nothing shows up $query = "SELECT posts.*, users1.followers FROM posts, users1 WHERE posts.userid = users1.followers AND posts.userid = '$user' ORDER BY posted DESC"; And when I try this one $query = "SELECT posts.*, users1.followers FROM posts, users1 WHERE posts.userid = users1.followers ORDER BY posted DESC"; It shows everything in the posts database, not just the one that matches the id. Can anybody help me out? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/151649-help-joining-2-databases/ Share on other sites More sharing options...
revraz Posted March 29, 2009 Share Posted March 29, 2009 Post the actual DB structure.. Table names and field names. Link to comment https://forums.phpfreaks.com/topic/151649-help-joining-2-databases/#findComment-796490 Share on other sites More sharing options...
Yeodan Posted March 30, 2009 Share Posted March 30, 2009 just make a query where you get the userid and the followers put the userid / followers in a variable make a new query based on the userid / followers variables to get the posts Link to comment https://forums.phpfreaks.com/topic/151649-help-joining-2-databases/#findComment-796492 Share on other sites More sharing options...
timmah1 Posted March 30, 2009 Author Share Posted March 30, 2009 Don't know how to show the fancy structure, so here's the sql posts CREATE TABLE IF NOT EXISTS `posts` ( `id` int(11) NOT NULL auto_increment, `userid` int(11) NOT NULL, `posted` datetime NOT NULL, `going` text NOT NULL, `city` varchar(50) NOT NULL, `state` varchar(25) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; users1 CREATE TABLE IF NOT EXISTS `users1` ( `id` int(11) NOT NULL auto_increment, `userid` int(11) NOT NULL, `followers` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; Link to comment https://forums.phpfreaks.com/topic/151649-help-joining-2-databases/#findComment-796494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.