Jump to content

Recommended Posts

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++; 
}

Link to comment
https://forums.phpfreaks.com/topic/137048-problem-updating-rankings/
Share on other sites

$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++;
}

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++;
}

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

 

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.