Jump to content

Archived

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

brown2005

can i connect three tables

Recommended Posts

Hi,

I have three tables

[b]members[/b]
members_id

[b]websites[/b]
websites_id

[b]websites_hits[/b]
websites_hits_id

rite in the website_hits table the websites_hits_id is 'members_id websites_id'

so wat i want to do is select all the websites from table websites that have no hits (websites_hits) for the member.............

Share this post


Link to post
Share on other sites
Your going to need to be alot more desciptive.

Share this post


Link to post
Share on other sites
say i have member_id is 1

i want to select all websites from table websites, for member 1, which have no hits in websites_hits

Share this post


Link to post
Share on other sites
Number [b]Member      websites      Hits[/b]
1          Brown          brown.org          0
2          Jack              jack.net            2

like that? 

Share this post


Link to post
Share on other sites
Like this;

Hi, member 1,

You have not viewed the following websites:-

www.test.co.uk
www.notatest.co.uk

so basically i want to select all the tables from websites that have no hits for member 1 in websites_hits.

Share this post


Link to post
Share on other sites
hmm..as far as I know you can connect id 'member' to 'websites'. And then try to make 'if' statement on website hit for every member id.

Share this post


Link to post
Share on other sites
Were going to need to see your table structures.

Share this post


Link to post
Share on other sites
CREATE TABLE `members` (
  `members_id` bigint(15) NOT NULL auto_increment,
  PRIMARY KEY  (`members_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

INSERT INTO `members` VALUES (1);

CREATE TABLE `websites` (
  `websites_id` bigint(15) NOT NULL auto_increment,
  `websites_website` varchar(255) NOT NULL default '',
  `websites_hits` bigint(15) NOT NULL default '0',
  `websites_hits_unique` bigint(15) NOT NULL default '0',
  `websites_date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`websites_id`)
) TYPE=MyISAM AUTO_INCREMENT=4 ;

INSERT INTO `websites` VALUES (1, 'www.fanaticfootball.co.uk', 0, 3, '2006-08-25 09:53:53');
INSERT INTO `websites` VALUES (2, 'www.google.co.uk', 0, 3, '2006-08-25 09:54:03');
INSERT INTO `websites` VALUES (3, 'www.bbc.co.uk/sport', 0, 2, '2006-08-25 09:54:10');

CREATE TABLE `websites_hits` (
  `websites_hits_id` varchar(15) NOT NULL default '0',
  `websites_hits_user` bigint(15) NOT NULL default '0',
  `websites_hits_website` bigint(15) NOT NULL default '0'
) TYPE=MyISAM;

INSERT INTO `websites_hits` VALUES ('1 1', 1, 1);
   

Share this post


Link to post
Share on other sites
Your website_hits_id column is a bad idea, having two pieces of data in one field... Why not just add an additional column, to make the relationships between the tables better?

That's just my opinion anyway.

As it is, you'll have to manipulate the data in that column, whether it be in the select statement, or in PHP once you have your recordset.

Regards
Rich

Share this post


Link to post
Share on other sites
I can't show you as I'm not certain what you're trying to achieve, but I do know that putting two pieces of data in the same column, just concatenated, is a bad idea.

Rich

Share this post


Link to post
Share on other sites
HuggieBear is right change your websites hit's table to this :

CREATE TABLE `websites_hits` (
  `members_id` varchar(15) NOT NULL default '0',
  `websites_id` bigint(15) NOT NULL default '0',
  `websites_hits` bigint(15) NOT NULL default '0'
) TYPE=MyISAM;

INSERT INTO `websites_hits` VALUES (1, 1, 0);

Then create relationships between member_id and websites_is to your websites_hits table then use :

"SELECT websites_id FROM websites_hits WHERE members_id = '$member' AND website_hits = 0"

Share this post


Link to post
Share on other sites

×

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.