Jump to content

mysql query not working in php


c1ockwerk

Recommended Posts

Hello, i have been at this one for a while and have broken down to ask for help. I have a SQL query that returns the correct results in sql but when i run it through php it does not return any results or errors.

 

Below is the SQL query and the php. The only difference is I use variables in PHP but they were tested post and pre query and they return the correct values.

 

SELECT Team.SchoolName, Team.Mascot, Player.PlayerFirst, Player.PlayerLast, COUNT( GameScoring.GoalID ) AS GoalTotal, Division.DLongDesc
FROM GameScoring
INNER JOIN Team ON GameScoring.TeamID = Team.TeamID
INNER JOIN Division ON Team.DivisionID = Division.DivisionID
INNER JOIN Player ON GameScoring.Scorer = Player.PlayerID
INNER JOIN Game ON GameScoring.GameID = Game.GameID
WHERE Team.DivisionID =4
AND Game.SeasonID =6
GROUP BY Scorer
ORDER BY GoalTotal DESC 
LIMIT 10

$query = mysql_query('SELECT Team.SchoolName, Team.Mascot, Player.PlayerFirst, Player.PlayerLast, COUNT( GameScoring.GoalID ) AS GoalTotal, Division.DLongDesc
FROM GameScoring
INNER JOIN Team ON GameScoring.TeamID = Team.TeamID
INNER JOIN Division ON Team.DivisionID = Division.DivisionID
INNER JOIN Player ON GameScoring.Scorer = Player.PlayerID
INNER JOIN Game ON GameScoring.GameID = Game.GameID
WHERE Team.DivisionID = \''.$division.'\'
AND Game.SeasonID = \''.$seasonid.'\'
GROUP BY Scorer
ORDER BY GoalTotal DESC 
LIMIT 10') or die(mysql_error());
// echo $seasonid; RETURNS CORRECT RESULT

// TABLE HEADER
echo '
<table id="t" cellspacing=0 cellpadding=1 class="t">
<th colspan=3>Scoring Leaders - '.$result['DLongDesc'].'</th>
<tr>
	<td>Player
	</td>
	<td>Team
	</td>
	<td>Goals
	</td>
</tr>';	
while($result = mysql_fetch_array($query) && mysql_num_rows($query) > 0)
{
echo '	
<tr>
	<td>'.$result['PlayerFirst'].' '.$result['PlayerLast'].'
	</td>
	<td>'.$result['SchoolName'].' '.$result['Mascot'].'
	</td>
	<td style="text-align:center;">'.$result['GoalTotal'].'
	</td>
</tr>';

}
echo '</table><br><br>';

 

 

Link to comment
https://forums.phpfreaks.com/topic/189583-mysql-query-not-working-in-php/
Share on other sites

There is not enough information here to provide you with a reason, how are you getting the values? Are you assuming that register_globals is on and it could be off? Was this working before...

 

But either way, that is not enough information to tell you why you are not getting any results from the query with the PHP code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.