Jump to content


Photo

can i connect three tables


  • Please log in to reply
11 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 25 August 2006 - 08:16 AM

Hi,

I have three tables

members
members_id

websites
websites_id

websites_hits
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.............


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 August 2006 - 08:26 AM

Your going to need to be alot more desciptive.

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 25 August 2006 - 08:30 AM

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

#4 Iyad

Iyad
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBalikpapan

Posted 25 August 2006 - 08:43 AM

Number Member      websites      Hits
1          Brown          brown.org          0
2          Jack              jack.net            2

like that? 

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 25 August 2006 - 08:46 AM

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.

#6 Iyad

Iyad
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationBalikpapan

Posted 25 August 2006 - 08:55 AM

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.

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 August 2006 - 09:04 AM

Were going to need to see your table structures.

#8 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 25 August 2006 - 09:06 AM

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);
   

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 August 2006 - 09:35 AM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 25 August 2006 - 09:37 AM

wat ya mean... can u show me?


#11 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 August 2006 - 09:52 AM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#12 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 11:14 AM

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"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users