i got it going np but heres the problem.
My intent for this script is to do this.
- Check to see if the a record has changed.
- If Data has changed and the player exists already, we are going to update.
- If there is no player, we are adding a new one.
What it's doing is repeating the insert. ie.. each refresh say put's 100 names in the db. After each refresh, its putting the same people back in there in new rows. I just need those existing players updated and if there is a new player, we add the new one only.
<?php
$sql ="SELECT Name,
MapAvg / 10 AS mapaverage,
Kills / Maps AS fragavg,
RoundAvg,
Knifed + KnifeKills AS totalknifed, date
FROM Players WHERE date= '$thismonth' or date = '$lastmonth' ";
$result = mysql_query($sql);
while($s_score =mysql_fetch_array($result)) {
// Set the points for all players who do have stats
$score1=$s_score['mapaverage'] * 100;
$score2=$s_score['fragavg'] * 10;
$score3=$s_score['RoundAvg'] * 10;
///////////////////////////////////////////////////
if ($s_score['mapaverage'] > 112) {
$score10= 1000;
} else {
$score10=0;
}
if ($s_score['fragavg'] > 20) {
$score11= 1000;
} else {
$score11=0;
}
if ($s_score['RoundAvg'] > 90) {
$score12= 1000;
} else {
$score12=0;
}
$name = $s_score['Name'];
$totalscore= round($score1 + $score10 + $score2 + $score11 + $score3 + $score12 ,2);
$query="SELECT Players.date, Players_Rank.Name FROM Players, Players_Rank WHERE `Players_Rank.Name` = '$name'
AND Players.date= '$thismonth' or date = '$lastmonth'"or die("could not select");
$newResult = mysql_query($query);
if ($row=mysql_fetch_array($newResult)) {
$nameSql="UPDATE Players_Rank set `Data` = '$totalscore' WHERE `Name`= '$name' " or die("could not update");
} else {
$nameSql="INSERT INTO Players_Rank (Name,Data) VALUES ('$name','$totalscore')" or die("could not insert");
} // end if else.
$nameResult = mysql_query($nameSql);
}
?>