Jump to content


Photo

php + mysql querry - too many results!


  • Please log in to reply
3 replies to this topic

#1 jpjsmith

jpjsmith
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationUSA

Posted 04 June 2003 - 12:17 PM

with php, i am querrying a mysql database and getting too many resluts returned. when i should retrive one record i get back 30+ of the same record. i querried the db directly and get one result - i am POSITIVE one result is correct.

this is my (rather long) sql statement:

$sql = \"SELECT Batting.yearID, Batting.teamID, Batting.lgID, Batting.G, Batting.AB, Batting.R, Batting.H, Batting.2B, Batting.3B, Batting.HR, Batting.RBI, Batting.SB, Batting.CS, Batting.BB, Batting.SO, Batting.IBB, Batting.HBP, Batting.SH, Batting.SF, Batting.GIDP, Teams.name

FROM Teams, Batting

where Batting.teamID=Teams.teamID AND Batting.playerID =\'$playerID\' AND Batting.yearId = \'$year\' \";


i just don\'t see where i went worng! anyone have any ideas?
(i added the spaces here just to make it eaiser to read)
:?: :?:

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 04 June 2003 - 12:59 PM

To me the query looks fine :roll:

Can u put more of ur code?
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 jpjsmith

jpjsmith
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationUSA

Posted 04 June 2003 - 08:20 PM

this is pretty much everything to do with the querry. its pretty basic and ive used this code several times with out any problems. i must be missing something!

<? include(\'dbconnect.php\'); ?>

<?
$playerID = $_GET[\'playerID\'];
$year = $_GET[\'year\'];

$result = @mysql_query($sql,$connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

$year = $row[\'yearID\'];
$teamid = $row[\'Batting.teamID\'];
$league =$row[\'lgID\'];
$games=$row[\'G\'];
$ab=$row[\'AB\'];
(all the variables are here, i cut them out for the sake of brevity )

$batting_data .=
\"<tr><td class=\'head\'><h3 class =\'head\'>Year</h3></td><td class=\'head\'><h3 class =\'head\'>Team</h3></td><td class=\'head\'><h3 class =\'head\'>League</h3></td><td class=\'head\'><h3 class =\'head\'>Games</h3></td><td class=\'head\'><h3 class =\'head\'>At Bats</h3></td> </tr>\";
(etc...)

}

?>

later on the page...
<? echo \"$batting_data\"; ?>

thanks for taking a look!

#4 jpjsmith

jpjsmith
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationUSA

Posted 04 June 2003 - 08:24 PM

i changed one line to


$batting_data =
\"<tr><td class=\'head\'><h3 class =\'head\'>Year</h3></td><td class=\'head\'><h3 class =\'head\'>Team</h3></td><td class=\'head\'><h3 class =\'head\'>League</h3></td><td class=\'head\'><h3 class =\'head\'>Games</h3></td><td class=\'head\'><h3 class =\'head\'>At Bats</h3></td> </tr>
<tr><td><h3>$year</h3></td><td>... \";

i took out the \".\" after $batting_data before the =
i guess it just didn\'t like it in this case.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users