update database with new csv
|
|
The script I need to get working should upload 3 data files from a different website and update 3 table in the database with the new information. Then it should compare the registered forum users with the updated tables and return the names of any members who are are no longer in the tribe.
The database is called twfamily_smf1. There are 3 tables I added called tw_player, tw_tribe and tw_village. Right now the tables have nothing in them since I can't get the code to run and I also can't seem to import the data in phpmyadmin (it imports the first line and stops). It shows in MySQL Account Maintenance twfamily_update is a user in the twfamily_smf1 and has all privileges. The file is called update.php and is saved in /public_html/Aggression/update.
Can someone tell me what I am not doing right?
[code]
";
$village_info = "http://en13.tribalwars.net/map/village.txt.gz";
$player_info = "http://en13.tribalwars.net/map/tribe.txt.gz";
$ally_info = "http://en13.tribalwars.net/map/ally.txt.gz";
mysql_query("USE $database");
mysql_query("DELETE FROM $prefix"."player");
$lines = gzfile($player_info);
if (!is_array($lines))
die("Could not open player info file.");
foreach($lines as $line) {
list ($id, $name, $ally, $villages, $points, $rank) = explode(',', $line);
$name = prepare($name);
mysql_query("INSERT INTO $prefix"."player VALUES ($id, '$name', $ally, $villages, $points, $rank)");
}
echo "Inserted player info. "; mysql_query("DELETE FROM $prefix"."ally"); $lines = gzfile($ally_info); if (!is_array($lines)) die("Could not open ally info file."); foreach($lines as $line) { list ($id, $name, $tag, $members, $villages, $points, $all_points, $rank) = explode(',', $line); $name = prepare($name); $tag = prepare($tag); mysql_query("INSERT INTO $prefix"."ally VALUES ($id, '$name', '$tag', $members, $villages, $points, $all_points, $rank)"); } echo "Inserted ally info. "; mysql_query("DELETE FROM $prefix"."village"); $lines = gzfile($village_info, "r"); if (!is_array($lines)) die("Could not open village info file."); foreach($lines as $line) { list ($id, $name, $x, $y, $player_id, $points, $rank) = explode(',', $line); $name = prepare($name); if (!mysql_query("INSERT INTO $prefix"."village VALUES ($id, '$name', $x, $y, $player_id, $points, $rank)")) { echo mysql_error(); break; } } echo "Inserted village info. "; $members = mysql_query("SELECT memberName FROM smf_members"); while ($member = mysql_fetch_row($members)) { mprint_r($member); $member_stat = mysql_query("SELECT ally, name FROM $prefix"."player WHERE name = '$member[0]'"); $member_info = mysql_fetch_row($member_stat); if (!$member_info[1]) { echo "** $member[0] is not an Aggression Family Member. "; continue; } mprint_r($ally_id); $ally = mysql_query("SELECT name FROM $prefix"."ally WHERE id = '$member_info[0]'"); $ally_name = mysql_fetch_row($ally); mprint_r($ally_name); if (!$ally_name[0]) { echo "*$member[0] is not in any tribe "; continue; } if (($ally_name[0] != "R@") && ($ally_name[0] != "D@") && ($ally_name[0] != "R@A") && ($ally_name[0] != "D@A")) echo "$member[0] is in $ally_name[0] "; } function prepare($string) { return addslashes(urldecode($string)); } function mprint_r($array) { echo " ";
print_r($array);
echo "";
}
?>
[/code]
|
|
|
Edit your post, replace |
|
|
Gollum, I'm sure you meant
because the other way is bad and wrong and illegal. -Joel |
