Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Combining data from 2 tables.
Old 04-28-2005, 01:35 PM Combining data from 2 tables.
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
I used to know this, but haven't done it for more than a year.

1) How do you combine data from two tables?

2) Furthermore, is it possible to include an if statement, so that...

Code:
if(data is from table 1) font-color should be red
elseif(data is from table 2) font-color should be blue
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 04-28-2005, 01:52 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
what do you mean combine them? as in place them in one table or simply extract data from two tables and place them on one page? The latter would be simple.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-28-2005, 03:53 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Fambi, the two tables must have a relationship -- a key on each that is shared. For example, I have a table MOVIES with movieid, title and directorid; and the director field is an int. I have a directors table that has a directorid, name, birth day, favorite color, etc. The directorid field on the directors table holds a unique number for each row that uniquely identifies it -- that's the primary key. The directorid field in the MOVIES table is a reference to the directorid field on the directors table. That is called a foreign key.

Now that the relationship is there, I can create a query which joins the two sets of data together. Let's say I wanted to find out the name and favorite color of the director of a movie called "FRANK." So the movie title lives in one table (movies) and the favorite color and name live in the other (directors).


Code:
SELECT d.birthDay, d.Name FROM directors d INNER JOIN movies m ON d.directorid=m.directorid WHERE m.title = 'FRANK'
This is a called a "join."
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 04-28-2005, 07:43 PM
Skilled Talker

Posts: 57
Trades: 0
yea kyrnt nailed that one
__________________

Please login or register to view this content. Registration is FREE
ruick is offline
Reply With Quote
View Public Profile
 
Old 04-28-2005, 08:25 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
learn something new everyday, dámn, i should really read up on my SQL
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-28-2005, 11:00 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Cool. Thanks.

Now is there anyway of identifying which data has come from which table?

If not, i'll put some reference in one table that isn't in the other, and then call an if statement to identify which info has come from which.

THanks again.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 05-24-2005, 06:31 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
OK. I finally sat down to implement this and i think i may have misexplained what i am trying to do.

Basically, i am trying to compile all the messages received and all the messages sent into a single table. They share many same fields such as the message body & date and the primary between them is the username.

Any ideas?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 05-24-2005, 06:45 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
Same u stilll use join if i'm rite
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 05-24-2005, 06:47 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
When i tried it, the best i could do was compile the corrseponding data from the two tables into 1 single row. What i would like to do is keep the data from the two tables in seperate rows.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 05-24-2005, 10:43 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
In the end, i called the data from both tables seperately and stuck the results into a single array.

I then used array_multisort to sort them accordingly and achieved my goal.

Thanks for the help everyone.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Combining data from 2 tables.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.97543 seconds with 12 queries