I have a PHP page written to parse a remote XML page - take the data, assign it to variables, and INSERT it into a local MySQL database. Works like a charm...
However, my next phase is this. Instead of erasing the entire table every time this data updates (which is how I have it written now), I would like to add some fields to the table for local additional info. This means I will need to UPDATE instead of DELETE and INSERT. Here are the two subs I have now that accomplish the insert...
function print_name_tr($char)
{
global $GROUP;
// Assigning XML output to PHP variables
$daname = $char->name;
$dalaston = $char->laston;
$daclass = $char->class;
$dalevel = $char->level;
$datotalrp = $char->totalrp;
$dalastweekrp = $char->lastrp;
$daanon = $char->anon;
// Connecting to the MySQL database.
MYSQL_CONNECT(localhost, USER, PASS) OR DIE("Unable to connect to database");
@mysql_select_db("DBNAME") or die("Unable to select database");
// INSERTING data...here is where my update attempt failed.
$sqlupdate2 = "INSERT INTO da_updates VALUES('','$daname','$dalaston','$daclass','$dalevel','$datotalrp','$dalastweekrp','$daanon')";
$result = MYSQL_QUERY($sqlupdate2);
// Visible output on the php page...using this for error checking
echo <<<EOT
$daname, $dalevel - Updating...<br>
EOT;
}
// This function calls the INSERT function, and starts the loop for the multiple $daname 's.
function print_default()
{
global $CHARS;
global $SCRIPT_NAME, $sortby;
global $server, $groupid;
foreach($CHARS as $char)
{
print_name_tr($char);
}
}
Now the $daname XML variable does not change...so I should just be able to change the INSERT INTO to an UPDATE ... WHERE da_name=$daname ... but that didn't work.
Any suggestions or help? Thanks!