Well i got a very odd problem. Im trying to import the data from the WoW armory, and in the process add this information to my own database underneath a table called user.
Now im checking while adding new members also if all the information about the current members is still correct using (keep in mind fixing all the sql injection problems is something i will do after this):
@$json = file_get_contents("http://$region.battle.net/api/wow/guild/$realm/$guild?fields=members,achievements");
if($json == false)
{
throw new Exception("Failed To load infomation. check setup options");
}
$decode = json_decode($json, true);
foreach($decode['members'] as $p) {
$mrank = $p['rank'];
$mname = $p['character']['name'];
$mclass = $p['character']['class'];
$mrace = $p['character']['race'];
$mlevel = $p['character']['level'];
$mgender = $p['character']['gender'];
$check = mysql_query("SELECT * FROM user WHERE charactername='$mname'");
if($check == false)
{
die("Sql query failed");
}
if(mysql_num_rows($check) != 0)
{
if($mlevel !== $check['level'])
{
mysql_query("UPDATE user SET level='$mlevel' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "level $mname<br />";
}
if($mclass !== $check['class'])
{
mysql_query("UPDATE user SET class='$mclass' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "class $mname<br />";
}
if($mrace !== $check['race'])
{
mysql_query("UPDATE user SET race='$mrace' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "race $mname<br />";
}
if($mgender !== $check['gender'])
{
mysql_query("UPDATE user SET gender='$mgender' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "gender $mname<br />";
}
if($mrank !== $check['rank'])
{
mysql_query("UPDATE user SET rank='$mrank' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "rank $mname<br />";
}
$pCount = $pCount + 1;
}
else
{
//add new user otherwise
$sql="INSERT INTO user (charactername, class, race, level, gender, rank) VALUES ('$mname','$mclass','$mrace','$mlevel','$mgender','$mrank')";
$nCount = $nCount + 1;
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
}
echo "$nCount new members added.<br />";
echo "$pCount member(s) already existed.<br />";
echo "$uCount member(s) got updated <br />";
But now is the problem, using this code the update part so all the:
if($mlevel !== $check['level'])
{
mysql_query("UPDATE user SET level='$mlevel' WHERE charactername='$mname'");
$uCount = $uCount + 1;
echo "level $mname<br />";
}
Run anyways, and i dont understand why. I compared the data and both are equal when echo'ed. So using !== should as far as i know only fire if they are not identical. With the current situation i have the update script running 800 times. And with that also literally updating all data in the user table 800 times. While this as far as i know should not be necessary.
Any help would be greatly appreciated.