Page 1 of 1

About DB is PHP

Posted: Wed Jul 24, 2002 5:47 pm
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

Posted: Wed Jul 24, 2002 6:03 pm
by jason
Well, the real question is why do you need 2 databases?

Posted: Wed Jul 24, 2002 6:58 pm
by protokol
It is possible that he meant a 2nd "table" and not a 2nd "database"

Posted: Wed Jul 24, 2002 9:10 pm
by psn
Yeah I mean 2 Tables is it possible.

Posted: Wed Jul 24, 2002 11:33 pm
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

Posted: Thu Jul 25, 2002 1:00 am
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.

Posted: Thu Jul 25, 2002 3:07 am
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

Posted: Thu Jul 25, 2002 9:39 am
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");

Posted: Thu Jul 25, 2002 9:54 am
by twigletmac
Which is why he needs some error handling and a good read of the MySQL manual regarding SELECT...

Mac