Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.