Forum Moderators: coopster

Message Too Old, No Replies

if(!isset($ GET

         

skoff

4:36 am on Nov 18, 2008 (gmt 0)

10+ Year Member



Hi, yeah it's me... again

now i have another problem. I'll give your some informations to be more clear.

table : schedule
columns : gameno,hometeam,awayteam,homescore,awayscore,ot

Ok so what i want to do is create a scorebox that show the last game from the team. I want to put this on the same page as i put stats. The page with stats is teams.php?teams=ana and it shows me the stats from this team. I want to show the last game from the team i choose. If i write teams.php?team=ana i want to show the last game informations from anaheim. So the link would look like this teams.php?team=ana&boxscore=ana or whatever it is.. its just a supposition. I made a code but i miss some informations.. like if when i make my select i can only choose if the last game they played was home or away.. i cant have the real last game... so here's the code to help a little bit.. i dont know if i'm that clear but the only thing i want to is to show the last game played by the team.

This is the code to only show the scorebox of the last game played away :
<html><style type="text/css">
<!--
body,td,th {
font-family: verdana;
font-size: 12px;
}
-->
</style>
<body>

<table>

<?php

$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
mysql_select_db("test");
if(!isset($_GET['awayteam'])) {
echo 'Category not specified';
die;
}
$result = mysql_query("SELECT hometeam,homescore,awayteam,awayscore from schedule where hometeam or awayteam= '" . mysql_real_escape_string($_GET['awayteam'])."' order by GameNo desc limit 1") or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
echo "<tr><td align='left'>" . $row["hometeam"] . "</td><td align='center'>" . $row["homescore"] . "</td></tr>";
echo "<tr><td align='left'>" . $row["awayteam"] . "</td><td align='center'>" . $row["awayscore"] . "</td></tr>";
}

mysql_close();

?>

</table>

</body>
</html>

Anyango

4:51 am on Nov 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are sending variable named "team" to teams.php, like this

teams.php?team=ana

try replacing your query with these 2 lines

$team=mysql_real_escape_string($_GET['team']);
$result = mysql_query("SELECT hometeam,homescore,awayteam,awayscore from schedule where hometeam = '$team' or awayteam='$team' order by GameNo desc limit 1") or die(mysql_error());

And, oh change your IF condition to cate for the variable "team" not for awayteam

if(!isset($_GET['team']))

[edited by: Anyango at 4:54 am (utc) on Nov. 18, 2008]

skoff

5:18 am on Nov 18, 2008 (gmt 0)

10+ Year Member



thanks it works but the thing is i want to have the very last game played it could be a home game or a away game..

skoff

5:26 am on Nov 18, 2008 (gmt 0)

10+ Year Member



this does more like a random choice.. and i dont get it because i wrote order by gameno desc limit 1...

skoff

6:03 am on Nov 18, 2008 (gmt 0)

10+ Year Member



i found the problem i didnt use the good datatype in the column of my table

Anyango

6:55 am on Nov 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea because that query should return the most recently played game for that team, doesn't matter even if team was home team or away team.