Current location: Hot Scripts Forums » Programming Languages » PHP » pulling data out from 3 database tables


pulling data out from 3 database tables

Reply
  #1 (permalink)  
Old 08-01-04, 07:48 PM
anhhuan anhhuan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Question pulling data out from 3 database tables

when i do select to pull certain data out of the member table how can i also pull the related information from other talble as well

or should i make one big table??


PHP Code:

CREATE TABLE member (

memberID INT NOT NULL AUTO_INCREMENT,
lastName VARCHAR (50),
firstName VARCHAR (50),
address VARCHAR (255),
phone CHAR (15),
PRIMARY KEY (memberID));

CREATE TABLE primary (
primaryID INT NOT NULL AUTO_INCREMENT,
lastName VARCHAR (50),
firstName VARCHAR (50),
address VARCHAR (255),
phone CHAR (15),
PRIMARY KEY (primaryID ));

CREATE TABLE second (
secondID INT NOT NULL AUTO_INCREMENT,
lastName VARCHAR (50),
firstName VARCHAR (50),
address VARCHAR (255),
phone CHAR (15),
PRIMARY KEY (secondID)); 
Reply With Quote
  #2 (permalink)  
Old 08-01-04, 08:07 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
SELECT * FROM member, primary, second
Reply With Quote
  #3 (permalink)  
Old 08-01-04, 08:12 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
I noticed your columns look the same, so you may just want to make 3 separate queries.
Reply With Quote
  #4 (permalink)  
Old 08-01-04, 09:10 PM
anhhuan anhhuan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
it just sample there will be alittle bit differernt
so basicly i just select from all 3 ??
i just wonder like can i just do

PHP Code:

SELECT memberID FROM member 

and it will pull all the informations of this member even the data is in diffrent table and display this member and all of his informations only
Reply With Quote
  #5 (permalink)  
Old 08-01-04, 09:31 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
No, you'll want to change that to:

$query = SELECT * FROM member WHERE memberID = $memberid

This way all your results are for that member only.
Reply With Quote
  #6 (permalink)  
Old 08-02-04, 12:26 AM
darkfreak's Avatar
darkfreak darkfreak is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
You may also want to get familiar with the JOIN -syntax. I'm not going to try to explain it here exactly but there's a good short tutorial at w3schools.com. One thing you should take a note of is the if you JOIN multiple tables in one, you cannot have many columns with the same name - instead you will have to rename them something like:

SELECT table1.col1 AS t1c1, table2.col2 AS t2c1, ... FROM table1 LEFT JOIN table2 WHERE table1.foreignkey=table2.key

where, for example, both table1.col1 and table2.col2 can be something like customers.LastName and salespeople.LastName (like in a case if you would like to get the names of customers and salespeople returned in the same result table).

Check here for better explanation:

http://www.w3schools.com/sql/sql_join.asp

Last edited by darkfreak; 08-02-04 at 12:29 AM.
Reply With Quote
  #7 (permalink)  
Old 08-07-04, 09:38 PM
anhhuan anhhuan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
thanks guys
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script for uploading data from local database to production database pual_cruzs PHP 1 07-06-04 12:44 AM
can i things into 2 tables in the same database on 1 script? tisza PHP 3 07-01-04 04:11 AM
2 questions 1-Webbased database access. 2-PDF data retrieval Mehre PHP 1 04-11-04 04:20 AM
php code not pulling data from DB simone PHP 1 11-22-03 02:08 AM


All times are GMT -5. The time now is 04:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.