18
Ok I have a question here for you guys. Basically what I am doing is this. I have figured out how to take the arrayed values listed as player names on the server, and insert them into the db. The problem is, is that every time that the script refreshes, it adds more entries to the table. Basically what I am wanting to do is script it such that it compares who is on the server to who is in the db. If it finds that the person that is on the server is still in the db, it does nothing, is performs an UPDATE, and moves on to the next arrayed value. If it finds that there is a person on the server that is NOT in the db, it adds that entry. If it finds that none of the people on the server match who is in the db, then it deletes the entry from the db, which keeps the queried players the same as what the arrayed values on the server are. Here is the code that I am working on. It inserts the values fine, but doesn't delete older entries. What am I doing wrong here.
global $gameserver_ip;
$time=time();
$playername = $teams['player'][$i]; //<== VARIABLE FROM SERVER QUERY, LISTS EACH PLAYER IN AN ARRAY.
$q=@mysql_query("SELECT pname FROM xoops_bf2query_info WHERE pname='$playername'");
if (@mysql_num_rows($q)==0) {
// if not, create dummy entry
@mysql_query("INSERT INTO xoops_bf2query_info SET s_time='$time', p_s_ip='$gameserver_ip', pname='$playername'");
}else{
$deleteuser = @mysql_query("SELECT pname FROM xoops_bf2query_info WHERE pname='$playername'");
if (@mysql_num_rows($deleteuser)==0) {
$query_bf2query_playername = "SELECT * FROM xoops_bf2query_info";
$bf2query_playername = @mysql_query($query_bf2query_playername);
$row_bf2query_playername = mysql_fetch_assoc($bf2query_playername);
$totalRows_bf2query_playername = mysql_num_rows($bf2query_playername);
$varpname = $row_bf2query_playername['pname'];
@mysql_query("DELETE FROM xoops_bf2query_info WHERE pname='$varpname'");
}else{
@mysql_query("UPDATE xoops_bf2query_info SET s_time='$time', p_s_ip='$gameserver_ip', pname='$playername' WHERE pname='$playername'");
}
}
Any and all help is GREATLY appreciated!!!