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
listing from two db tables
Old 05-23-2009, 08:10 AM listing from two db tables
Super Talker

Posts: 134
Trades: 0
i have 2 db tables, something like:

table1
index,
field1,
field2

table2
index,
pid,
field1,
field2


table2.pid is linked with table1.index

a record in table1 can be linked with 0, 1 or more records in table2


now i want a listing from all the records from table1 with at least 1 record linked in table2, and for each of these records all the records from table2

output something like:

table1.field1 table1.field2

table2.field1 table2.field2

------------------------------

table1.field1 table1.field2

table2.field1 table2.field2
table2.field1 table2.field2


how is the best way to code this in php
__________________

Please login or register to view this content. Registration is FREE

Check out the Facebook Clone build with Jcow SNS at
Please login or register to view this content. Registration is FREE
, it is free and it always will be
Falcone is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-23-2009, 03:55 PM Re: listing from two db tables
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
you can do a LEFT JOIN in your Sql call which should link them as you want them with table1 being referenced first

Code:
 
SELECT * FROM table2 LEFT JOIN table1 ON table1.field1 = table2.field1 WHERE ....
personally id create a VIEW in your MYSQL Server and let the database handle the join
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to listing from two db 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 0.10161 seconds with 12 queries