|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Linking MySQL table problem
Hi all,
I am currently having a few issues with linking 3 tables together to get info from each other and display on one page. I have this layout, the ones in bold are the table names - team id name fullname bench id name submitted id team_id bench_id name system score Now the problem I am having is getting the tables to link where it says team_bench and bench_id. I have also tried to echo any of the info in the main submitted table, but nothing is displayed. I have no idea what is going wrong. Below is the code. I get the following error in Apache - Quote:
If someone could help me with this it'd be really appreciated. Code:
<html>
<body>
<font face="Arial">
<?php
// connect to server
mysql_connect( 'localhost',
'boardy_teamuk','t34muk')
or die( "Couldnt connect to server" .mysql_error
());
// select db
mysql_select_db('boardy_teamuk')
or die( "Couldnt connect to db" .mysql_error
());
{
}
mysql_query($sql);
// Retrive rows from table
$query = "SELECT 'submitted.*' 'team.name AS team_name FROM team' 'bench.name
AS bench_name FROM bench' 'JOIN bench WHERE submitted.bench_id = bench.id' 'JOIN team WHERE
submitted.team_id = team.id'"
;
$results = mysql_query($query
);
// print results
if($results)
{
while($table = mysql_fetch_object
($results))
{
// print out info";
$mid = $table -> id;
echo("$mid");
$team = $table -> team_name;
echo("$team");
$mname = $table -> name;
echo("$mname");
$bench = $table -> bench_name;
echo("$bench");
$score = $table -> score;
echo("$score");
}
}
else
{
die("Couldnt connect to db tables." .mysql_error
());
}
?>
</font>
</body>
</html>
Cheers Boardy |
|
#2
|
|||
|
|||
|
Firstly, remove your connection info mate... youre currently giving out the login stuff to your database.
|
|
#3
|
|||
|
|||
|
Secondly, I'd do this to select from several tables:
PHP Code:
t1 = the first table you like to select from t2 = the second table you like to select from table1 AS t1 this is where determine what t1 table really is, same thing for t2 of course. column1, 2, 3 is just the columns within the respective tables... change that to whatever suits your database setup. Not sure what you are trying to join here... I also sense that having several WHERE clauses within the same query might complicate things for you... |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Linking MySQL table problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|