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
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);
   
Link to comment
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
Link to comment
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"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.