Jump to content

can i connect three tables


brown2005

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.............
Link to comment
https://forums.phpfreaks.com/topic/18628-can-i-connect-three-tables/
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);
   
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
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"

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.