BigBrother Posted December 15, 2008 Share Posted December 15, 2008 I would appreciate some help here, I am attempting to update a league table based on points and goal diff which is working fine, however during this process I am also trying to attempt to identify if the team moved up / down or stays the same... any ideas why this is not working? $query = "SELECT * FROM Eden_Premiership ORDER BY points DESC, goal_diff DESC"; $result = mysql_query($query); $num = mysql_numrows($result); $i = 0; while ($i < $num) { $team_id = mysql_result($result,$i,"team_id"); $rank = $i + 1; if ($rank > $result[$i]['pos']) $ch = 1; if ($rank < $result[$i]['pos']) $ch = 2; if ($rank == $result[$i]['pos']) $ch = 0; mysql_query("UPDATE Eden_Premiership SET pos='$rank' WHERE team_id='$team_id'"); mysql_query("UPDATE Eden_Premiership SET change='$ch' WHERE team_id='$team_id'"); $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/ Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 $query = "SELECT * FROM Eden_Premiership ORDER BY points DESC, goal_diff DESC"; $result = mysql_query($query); $i = 1; while ($details = mysql_fetch_assoc($result)) { $team_id = $details["team_id"]; $rank = $i; if ($rank > $details['pos']) $ch = 1; if ($rank < $details['pos']) $ch = 2; if ($rank == $details['pos']) $ch = 0; mysql_query("UPDATE Eden_Premiership SET pos='$rank', change='$ch' WHERE team_id='$team_id'"); $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715769 Share on other sites More sharing options...
gevans Posted December 15, 2008 Share Posted December 15, 2008 **NOT TESTED** Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715773 Share on other sites More sharing options...
BigBrother Posted December 15, 2008 Author Share Posted December 15, 2008 Did not work I had to revert back to old script to make leage sort work again. $query = "SELECT * FROM Eden_Premiership ORDER BY points DESC, goal_diff DESC"; $result = mysql_query($query); $num = mysql_numrows($result); $i = 0; while ($i < $num) { $team_id = mysql_result($result,$i,"team_id"); $rank = $i + 1; mysql_query("UPDATE Eden_Premiership SET pos='$rank' WHERE team_id='$team_id'"); $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715821 Share on other sites More sharing options...
MasterACE14 Posted December 15, 2008 Share Posted December 15, 2008 this... $num = mysql_numrows($result); should be this... $num = mysql_num_rows($result); Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715825 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 You should really use debugging tools. For example adding this at the top of your script: ini_set ("display_errors", "1"); error_reporting(E_ALL); and: $result = mysql_query($query) or die(mysql_error()); $num = mysql_num_rows($result) or die(mysql_error()); // you would have found this syntax error a lot faster Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715841 Share on other sites More sharing options...
BigBrother Posted December 15, 2008 Author Share Posted December 15, 2008 Thanks for the input, however I still have not achived my original problem of also working out if the possition has changed and insert code to database. Regards BB Quote Link to comment https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/#findComment-715846 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.