Need some help on this one.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bimmer
Forum Newbie
Posts: 2
Joined: Sun Apr 18, 2004 1:07 pm

Need some help on this one.

Post by bimmer »

My intent for this script is to do this.

1. Check to see if the a record has changed.
2. If Data has changed and the player exists already, we are going to update.
3. 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.

Code: Select all

<?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);

}

?>
bimmer
Forum Newbie
Posts: 2
Joined: Sun Apr 18, 2004 1:07 pm

Post by bimmer »

no one? :/
Post Reply