PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old September 13th, 2002, 01:36 PM
mhoward mhoward is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 49 mhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Retrieving info from 2 MySQL Tables

I am trying to retrieve from 1 table the specific names of teams (no problem).

Then, what i want to do is for each of the team names, pull info from another mysql table where the details match the team name.

How can i do this?

I have tried...

$sql1 = "SELECT * FROM $team_table";
$result1 = mysql_query($sql1);

while ($team_data = mysql_fetch_array($result1))
{
$id = $team_data["id"];
$name = $team_data["name"];

$sql2 = "SELECT * FROM table2 WHERE team_name = '$name'";
$result2 = mysql_query($sql2);

while ($query_data = mysql_fetch_array($result2))
{
$client = $query_data["client"];
etc...

echo "etc etc etc";
}
}

All i get is 1 row output not all the info I want.

Any ideas?


Reply With Quote
  #2  
Old September 13th, 2002, 04:14 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Retrieving info from 2 MySQL Tables

try something like:

SELECT team_table.*, team_data.* FROM team_table, team_data WHERE team_table.name = team_data.name

obviously you need to work it out for your table schemas......

Reply With Quote
  #3  
Old September 16th, 2002, 07:51 AM
mhoward mhoward is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 49 mhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Retrieving info from 2 MySQL Tables

OK - I have changed my code to be...

$sql = "SELECT $team_table.*, $undercollection_table.* FROM $team_table, $undercollection_table WHERE $team_table.team_name = '$undercollection_table.SalesManager'";
$result = mysql_query($sql);
if (!$result) {
mysql_err();
exit; }

but how do I know specify what each column in each table is to be?

is it simply a case of
while ($query_data = mysql_fetch_array($result))
{
$name = $query_data["team_table.name"];
echo "ect etc etc...";
}
?

Sorry if it should be obvious!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Retrieving info from 2 MySQL Tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway