Incerc de ceva timp sa fac sa imi salveze informatiile jucatorului in baza de date, o data inserate vreau atunci cand gaseste din nou acel jucator sa ii adauge scor, timp, harta .
Insa acesta imi duplica continutul in loc sa adauge dupa nume (nickname='$player_nickname).
Ce este de facut ?
Acesta este codul :
Cod: Selectaţi tot
if (mysqli_num_rows($sql) > 0)
{
$insert_player_query2 = mysqli_query($db,"UPDATE players (nickname,score,time_online,mapname,sid) VALUES ($player_nickname','$player_score','$player_time','$mapname','$server_id') nickname='$player_nickname'");
} else {
$insert_player_query = mysqli_query($db,"INSERT INTO players (id,nickname,score,time_online,mapname,sid) VALUES ('','$player_nickname','$player_score','$player_time','$mapname','$server_id')");
}
}
Cod: Selectaţi tot
<?php
include('/db.php');
$server_query = mysqli_query($db,"SELECT id,ip,game FROM servers WHERE UNIX_TIMESTAMP()-last_update>180 ORDER BY rank_pts DESC");
while($server_row = mysqli_fetch_assoc($server_query)){
$server_id = $server_row['id'];
$server_ip = $server_row['ip'];
$server_game = $server_row['game'];
$last_update = time();
require_once('/GameQ.php');
$servers = array(
array(
'id' => $server_id,
'type' => $server_game,
'host' => $server_ip,
)
);
$gq = new GameQ();
$gq->addServers($servers);
$gq->setOption('timeout', 4); // Seconds
$gq->setFilter('normalise');
$results = $gq->requestData();
foreach($results as $data){
if($data['gq_online'] == "1"){
$hostname = mysqli_real_escape_string($db,$data['gq_hostname']);
$mapname = mysqli_real_escape_string($db,$data['gq_mapname']);
$num_players = mysqli_real_escape_string($db,$data['gq_numplayers']);
$max_players = mysqli_real_escape_string($db,$data['gq_maxplayers']);
$players = $data['players'];
$hostname = (!empty($hostname)) ? $hostname : '---';
$mapname = (!empty($mapname)) ? $mapname : '---';
$max_players = (!empty($max_players)) ? $max_players : '---';
if($hostname == "---" OR $mapname == "---" OR $max_players == "---"){
$update_query = mysqli_query($db,"UPDATE servers SET online='1', num_players='$num_players', last_update='$last_update' WHERE id='$server_id'");
} else {
$update_query = mysqli_query($db,"UPDATE servers SET online='1', hostname='$hostname', mapname='$mapname', num_players='$num_players', max_players='$max_players', last_update='$last_update' WHERE id='$server_id'");
}
//$del_player_query = mysqli_query($db,"DELETE FROM players WHERE sid='$server_id'");
foreach ($players as $player) {
$player_nickname = mysqli_real_escape_string($db,$player['gq_name']);
$player_score = mysqli_real_escape_string($db,$player['gq_score']);
$player_time = mysqli_real_escape_string($db,$player['time']);
$player_nickname = (!empty($player_nickname)) ? $player_nickname : 'anonymous';
$sql=mysqli_query($db, "SELECT * FROM players WHERE nickname='$player_nickname'");
if (mysqli_num_rows($sql) > 0)
{
$insert_player_query2 = mysqli_query($db,"UPDATE players (nickname,score,time_online,mapname,sid) VALUES ($player_nickname','$player_score','$player_time','$mapname','$server_id') nickname='$player_nickname'");
} else {
$insert_player_query = mysqli_query($db,"INSERT INTO players (id,nickname,score,time_online,mapname,sid) VALUES ('','$player_nickname','$player_score','$player_time','$mapname','$server_id')");
}
}
} else {
$update_query = mysqli_query($db,"UPDATE servers SET online='0',num_players='0' WHERE id='$server_id'");
//$del_player_query = mysqli_query($db,"DELETE FROM players WHERE sid='$server_id'");
}
}
}
?>