Jump to content

Help joining 2 databases


timmah1

Recommended Posts

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

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 ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.