Forum Moderators: coopster

Message Too Old, No Replies

specific data per id

         

goody2

5:00 pm on Jul 27, 2011 (gmt 0)

10+ Year Member



Hi all, i am looking to pull data from a specific location. The location is the "subconference" in the teams table with a specific id. Here is my code or what im working with....


<?php
// Connects to your Database
$teamid = $_REQUEST["id"];

$sql = 'select *from season11 join teams WHERE season11 . team =teams . teamnameseason AND teams . subconference ="Northwest" ORDER BY `season11` . `P` DESC';

$data = mysql_query($sql)
or die(mysql_error());




Print "<table width = 240>";
Print "<th width=80 align = left bgcolor=#ebf0f6>Northwest</th>";Print "<th bgcolor=#ebf0f6>GP</th>";
Print "<th bgcolor=#ebf0f6>W</th>";
Print "<th bgcolor=#ebf0f6>L</th>";
Print "<th bgcolor=#ebf0f6>Pts</th>";
Print "<th bgcolor=#ebf0f6>GF</th>";
Print "<th bgcolor=#ebf0f6>GA</th>";
Print "<th bgcolor=#ebf0f6>L10</th>";




while($info = mysql_fetch_array( $data ))
{
$wins = $info['W'];
$OTW = $info['OW'];
$totalwins = $wins + $OTW ;


$teamnameseason = $info['teamnameseason'];
Print "<tr>";
Print "<td align = left width=80>".$info['team'] . "</td> ";
Print "<td align = center>".$info['GP'] . "</td> ";
Print "<td align = center>";
Print $totalwins;
Print "</td> ";
Print "<td align = center>".$info['L'] . "</td> ";
Print "<td align = center>".$info['P'] . "</td> ";
Print "<td align = center>".$info['GF'] . "</td> ";
Print "<td align = center>".$info['GA'] . "</td> ";
Print "<td align = center>".$info['L10'] . "</td> ";



}



Print "</table>";
?>

<?php
include 'closedb.php';
?>




Where it says subconference ="Northwest" i need it to change per id...

Still abit new so dont be surprised at my questions... Thanks a bunch....

httpwebwitch

7:57 pm on Jul 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$teamid = $_REQUEST["id"];
// ^^ change this. use $_GET or $_POST, not $_REQUEST.
$teamid = $_GET["id"];

if (!is_numeric($teamid)){die();} // to prevent SQL injection

without knowing your database schema, I think your query needs to be something like this:

$sql = "select * from season11,teams WHERE season11.team = teams.teamnameseason AND teams.id=" . $teamid . " ORDER BY season11.P DESC";

while debugging, you can print($sql), and look at the query. Cut and paste it into a SQL Query analyzer and see if it produces errors, or gets you the info you expect.

goody2

3:21 am on Jul 28, 2011 (gmt 0)

10+ Year Member



ok. i will give her a shot.. Thanks a bunch..

goody2

3:58 am on Jul 28, 2011 (gmt 0)

10+ Year Member



Thanks httpwebwitch. I have sent you a PM with a update...


Again... Thanks So Much!

httpwebwitch

12:22 pm on Jul 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh, you want the teams that belong to the subconference that the team with teamid belngs to.

Do a subselect to get the conference, and incorporate that datum into the WHERE clause of the overall query.

$sql = "select * from season11,teams WHERE season11.team = teams.teamnameseason AND teams.subconference = (SELECT subconference from teams WHERE id = " . $teamid . ") ORDER BY season11.P DESC";

goody2

2:58 pm on Jul 28, 2011 (gmt 0)

10+ Year Member



hehe... sorry i guess i didnt explain myself to well. thanks again..