update rows with combined results

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   update rows with combined results
Azrael
CZ Newbie
Azrael has been a member for over 20 year's 20 Year Member
Website:
Status: Offline
Joined: Jun 06, 2004
0.00 posts per day
Posts: 6
Points: 941
   
Hi guys, this is a standalone php question and not a PHP-NUKE question........so my apologies if it's in the wrong forum, but i didn't see any other forum for PHP.

Im trying to combine a set of rows in my mysql table for a merge script, but the result i'm getting is incorrect.

the table setup:
1 row consists of the collumns:
id, player, kills, deaths, murders, suicides, knifings, headshots, medic_saves, revives, pspattempts, psptakeovers, doublekills, score_1, score_2, score_3, time, games, wins, server, game_type, last_played.

theres a different row for each server (i have 5 different server) and for each game_type per server (7 game_types)
so there will be a row for server 1 gametype 1, server 1 gametype 2, server 2 gametype 1, ect.

the place i think i am going wrong is that i think my script is adding the combined stats of all the rows to each row, where i need it only to add the combined values from query 1 to query 2 together only if the server and gametype match.

heres the script i wrote so far:


  <?
if($Submit) 
{

$plyr1 = htmlspecialchars(base64_encode($player1));
$plyr2 = htmlspecialchars(base64_encode($player2));

$dbhost     = "$dbh";   // Database host
$dbname     = "$dbn";   // Database name
$dbusername = "$dbun";      // Database user name
$dbuserpw   = "$dbpw";         // Database password

$link_id = mysql_connect($dbhost,$dbusername,$dbuserpw)
         or die("Could not connect to MySQL.");
//echo("Connection Successfull.<br>");
$selected = mysql_select_db($dbname,$link_id)
         or die("Could not select database");
//echo("Selection Successfull.");

$player1q = mysql_query("SELECT * FROM chronos_players WHERE name='$plyr1'");
while($row1 = mysql_fetch_array($player1q)){                                   
$pl1id = $row1["id"];
$rat1 = $row1["rating"];

$player2q = mysql_query("SELECT * FROM chronos_players WHERE name='$plyr2'");
while($row2 = mysql_fetch_array($player2q)){                                   
$pl2id = $row2["id"];
$rat2 = $row2["rating"];

if ($pl1id == "") {echo "invalid player";}
else{
$query7 = mysql_query("UPDATE chronos_players SET
                 rating        = '".$row1["rating"]."'   + '".$row2["rating"]."'       
               WHERE id= '".$row1["id"]."'");}
            
$player1statsq = mysql_query("SELECT * FROM chronos_stats WHERE player='".$row1["id"]."'");
while($row3 = mysql_fetch_array($player1statsq)){                                   
$pl1rec = $row3["id"];
$ser1 = $row3["server"];
$gmty1 = $row3["game_type"];

$player2statsq = mysql_query("SELECT * FROM chronos_stats WHERE player='".$row2["id"]."'");
while($row4 = mysql_fetch_array($player2statsq)){                                   
$pl2rec = $row4["id"];
$ser2 = $row4["server"];
$gmty2 = $row4["game_type"];
            
if ($ser1 == $ser2 && $gmty1 == $gmty2)
{$query1 = mysql_query("UPDATE chronos_stats SET
                 time         = time         + '".$row4["time"]."'       ,
                 kills        = kills        + '".$row4["kills"]."'       ,
                 deaths       = deaths       + '".$row4["deaths"]."'      ,
                 suicides     = suicides     + '".$row4["suicides"]."'    ,
                 murders      = murders      + '".$row4["murders"]."'     ,
                 headshots    = headshots    + '".$row4["headshots"]."'   ,
                 knifings     = knifings     + '".$row4["knifings"]."'    ,
                 medic_saves  = medic_saves  + '".$row4["medic_saves"]."'    ,
                 revives      = revives      + '".$row4["revives"]."'     ,
                 pspattempts  = pspattempts  + '".$row4["pspattempts"]."' ,
                 psptakeovers = psptakeovers + '".$row4["psptakeovers"]."',
                 doublekills  = doublekills  + '".$row4["doublekills"]."' ,
                   score_1      = score_1      + '".$row4["score_1"]."'      ,
                   score_2      = score_2      + '".$row4["score_2"]."'      ,
                   score_3      = score_3      + '".$row4["score_3"]."'      ,
                   games        = games        + '".$row4["games"]."'   ,
                   wins         = wins         + '".$row4["wins"]."'
               WHERE player = '".$row1["id"]."' HAVING server = $ser2 AND HAVING game_type = $gmty2");}
else{$query2 = mysql_query("INSERT INTO chronos_stats VALUES
                ('".$row4["id"]."','".$row3["player"]."','".$row4["kills"]."',
                 '".$row4["deaths"]."','".$row4["suicides"]."','".$row4["murders"]."',
                 '".$row4["headshots"]."','".$row4["knifings"]."','".$row4["medic_saves"]."',
                 '".$row4["revives"]."','".$row4["pspattempts"]."','".$row4["psptakeovers"]."',
                 '".$row4["doublekills"]."','".$row4["score_1"]."','".$row4["score_2"]."',
               '".$row4["score_3"]."'   ,'".$row4["time"]."','".$row4["games"]."',
               '".$row4["wins"]."','".$row4["server"]."','".$row4["game_type"]."',
               '".$row4["last_played"]."')");
}
}
}
}
}
echo"<table><tr><th><span class=style9>-</span></th></tr>";
echo "<tr><th>PLayers merged successfully</th></tr>";
echo "<tr><th><span class=style9>-</span></th></tr></table>";
} else { ?>


any help on achieving this would be GREATLY appreciated


Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
Your trying to connect to 5 diff. servers? You will need to explain a bit more what your trying to do.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: update rows with combined results
Azrael
CZ Newbie
Azrael has been a member for over 20 year's 20 Year Member
Website:
Status: Offline
Joined: Jun 06, 2004
0.00 posts per day
Posts: 6
Points: 941
   
Heres a shortened version of the rows in question and what i am trying to achieve.

I'm trying to combine the rows of player 2 and player 66 where the server value and game_type match.............so if the following rows exists:

player ='2', server= '1' and game_type= 'Deathmatch'
player ='66', server='1' and game_type='Deathmatch'

it would update player 2's row with the combined kills and deaths values of player 2 and player 66.

it should do this in all cases that the server value and game_type value match for both players.

i hope i explained it beeter this time.




rows.JPG
 Description:
N/A
 Filesize:  26.09 KB
 Viewed:  8185 Time(s)

rows.JPG




Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum