|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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...... |
|
#3
|
|||
|
|||
|
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! |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Retrieving info from 2 MySQL Tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|