About DB is PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psn
Forum Newbie
Posts: 13
Joined: Wed Jul 17, 2002 10:22 pm

About DB is PHP

Post by psn »

ok here the page script
<? include("left.php") ?>
<!--TEXT-->
<td VALIGN="top" bgcolor="white" width="500"><span class='print'>
<table>
<?
mysql_pconnect("localhost","root","");
mysql_select_db("psn");
$result = mysql_query("SELECT * FROM clubs where id='$id'");
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$club_name=$r["name"];
$manager=$r["manager"];
$wmessage=$r["wmessage"];
$history=$r["history"];
$honors=$r["honors"];
$stadium_address=$r["stadium_address"];
$picture=$r["picture"];
$website=$r["website"];
$emblem=$r["emblem"];
$league=$r["league"];


echo "<tr bgcolor='#333333'>
<td with='600'>
<div class='header'>$club_name</div>
</td>
<tr>
<td><img src='images/$emblem'></td>
<tr>
<td><img src='images/$picture'align='left'width='200'height='210'><b>Club Name</b>:$club_name<br><b>Managers Name:</b>$manager<br><b>Website Address:</b><a href='$website'target='blank'>$website</a></td><tr><td><b>Stadium Address</b>$stadium_address</td><tr><td><b>History:</b>$history</td><tr><td><b>Honors:</b>$honors</td>";} ?>
</table>
<td Valign="top" width="200">
<table>
<?
mysql_pconnect("localhost","root","");
mysql_select_db("psn");
$result = mysql_query("SELECT * FROM players ORDER by name ASC");
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$name=$r["name"];
$position=$r["position"];
$club=$r["club"];
$country=$r["country"];
$info=$r["info"];
$picture=$r["picture"];
$height=$r["height"];
$weight=$r["weight"];
$dob=$r["dob"];

echo "<tr><td><div class=''><a href='players.php?id=$id' class='body'>$name</a></div></td>";}?>

</body>
</html>
The second script that has players the DB is it possible to call 2 DB instead of one what would the code look like if possible
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Well, the real question is why do you need 2 databases?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

It is possible that he meant a 2nd "table" and not a 2nd "database"
psn
Forum Newbie
Posts: 13
Joined: Wed Jul 17, 2002 10:22 pm

Post by psn »

Yeah I mean 2 Tables is it possible.
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Post by virgil »

This should work.

Code: Select all

$result = mysql_query("SELECT  table1.fieldname, table2.fieldname FROM clubs where id='$id'");



This might, but I've never tried it.

Code: Select all

$result = mysql_query("SELECT  table1.*, table2.* FROM clubs where id='$id'");


Good luck :) Virgil
psn
Forum Newbie
Posts: 13
Joined: Wed Jul 17, 2002 10:22 pm

Post by psn »

no that didn't work. I'll try and explain it from the very beginning.
1) Ok we at the home page.
2) We open up Australia.php which has on the side all NSL clubs.
3) theres a php script which is getting from table clubs all the clubs that play in nsl.
4) We click on one of them.
eg clubs.php?id=$id or in browser clubs.php?id=1

5) this is were we see the profile. as we have a scipt that selects the id from the last page and we get the stuff heres the code

Code: Select all

<?
mysql_pconnect("localhost","xxxx","xxxx");
mysql_select_db("psn");
$result = mysql_query("SELECT * FROM clubs where id='$id'");
while($r=mysql_fetch_array($result))
&#123;    
    	$id=$r&#1111;"id"];
	$club_name=$r&#1111;"name"];
	$manager=$r&#1111;"manager"];
	$wmessage=$r&#1111;"wmessage"];
	$history=$r&#1111;"history"];
	$honors=$r&#1111;"honors"];
	$stadium_address=$r&#1111;"stadium_address"];
	$picture=$r&#1111;"picture"];
	$website=$r&#1111;"website"];
	$emblem=$r&#1111;"emblem"];
	$league=$r&#1111;"league"];


echo "<tr bgcolor='#333333'>
<td with='600'>
<div class='header'>$club_name</div>
</td>
<tr>
<td><img src='images/$emblem'></td>
<tr>
<td><img src='images/$picture'align='left'width='200'height='210'><b>Club Name</b>:$club_name<br><b>Managers Name:</b>$manager<br><b>Website Address:</b><a href='$website'target='blank'>$website</a></td><tr><td><b>Stadium Address</b>$stadium_address</td><tr><td><b>History:</b>$history</td><tr><td><b>Honors:</b>$honors</td>";&#125; ?>
6) On the side is suppose to be were the players that play for the club are but im getting an error.

Heres the players code

Code: Select all

<?
mysql_pconnect("localhost","","");
mysql_select_db("psn");
$result = mysql_query("SELECT * FROM clubs.name, players,name,id,club. ORDER by name ASC");
while($r=mysql_fetch_array($result))
&#123;    
	$id=$r&#1111;"id"];
	$name=$r&#1111;"name"];
	$position=$r&#1111;"position"];
	$club=$r&#1111;"club"];
	$country=$r&#1111;"country"];
	$info=$r&#1111;"info"];
	$picture=$r&#1111;"picture"];
	$height=$r&#1111;"height"];
	$weight=$r&#1111;"weight"];
	$dob=$r&#1111;"dob"];
	$club_name=$r&#1111;"name"];
echo "<tr><td><div class=''><a href='players.php?id=$id' class='body'>$name</a></div></td>";&#125;?>
From that we goto players.php which I'll just use the code like in the first one.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try this:

Code: Select all

$result = mysql_query("SELECT * FROM clubs.name, players,name,id,club. ORDER by name ASC") or die(mysql_error());
and read this:
http://www.mysql.com/doc/S/E/SELECT.html

Mac
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

what kinda query is this??

Code: Select all

$result = mysql_query("SELECT * FROM clubs.name, players,name,id,club. ORDER by name ASC");
the query itself looks like it has a buncha errors....

why don't you just do:

Code: Select all

$result = mysql_query("SELECT * FROM clubs ORDER BY name");
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Which is why he needs some error handling and a good read of the MySQL manual regarding SELECT...

Mac
Post Reply