c1ockwerk Posted January 24, 2010 Share Posted January 24, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/189583-mysql-query-not-working-in-php/ Share on other sites More sharing options...
premiso Posted January 24, 2010 Share Posted January 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/189583-mysql-query-not-working-in-php/#findComment-1000647 Share on other sites More sharing options...
c1ockwerk Posted January 24, 2010 Author Share Posted January 24, 2010 premiso, thanks for the quick response. the variables in the SQL statement are not the problem, i have changed them to be hard coded and the result is the same. what other information would you like? Quote Link to comment https://forums.phpfreaks.com/topic/189583-mysql-query-not-working-in-php/#findComment-1000655 Share on other sites More sharing options...
c1ockwerk Posted January 24, 2010 Author Share Posted January 24, 2010 found the problem removed && mysql_num_rows($query) > 0 from while($result = mysql_fetch_array($query) && mysql_num_rows($query) > 0) not its returning the results. Quote Link to comment https://forums.phpfreaks.com/topic/189583-mysql-query-not-working-in-php/#findComment-1000843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.