MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old November 21st, 2005, 06:47 AM
boardy boardy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 boardy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 46 m 52 sec
Reputation Power: 0
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:
[client 127.0.0.1] PHP Notice: Undefined variable: sql in /var/www/html/teamuk/index.php on line
18
[client 127.0.0.1] PHP Notice: Undefined property: stdClass::$id in /var/www/html/teamuk/
index.php on line 30
[client 127.0.0.1] PHP Notice: Undefined property: stdClass::$team_name in /var/www/html/teamuk/
index.php on line 32
[client 127.0.0.1] PHP Notice: Undefined property: stdClass::$name in /var/www/html/teamuk/
index.php on line 34
[client 127.0.0.1] PHP Notice: Undefined property: stdClass::$bench_name in /var/www/html/
teamuk/index.php on line 36
[client 127.0.0.1] PHP Notice: Undefined property: stdClass::$score in /var/www/html/teamuk/
index.php on line 38


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

Reply With Quote
  #2  
Old December 8th, 2005, 06:14 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
Firstly, remove your connection info mate... youre currently giving out the login stuff to your database.

Reply With Quote
  #3  
Old December 8th, 2005, 06:20 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
Secondly, I'd do this to select from several tables:

PHP Code:
 $sql "SELECT 
            t1.column1, t1.column2, t1.column3,
            t2.clumn1, t2.column2, t2.column3, 
        FROM 
            table1 AS t1, table2 AS t2"



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...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Linking MySQL table problem


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 | 
  
 





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