I'm having a problem getting my PHP IF condition to work which also involves issets. This is how the code is supposed to function on all conditions:
(It's basically a leaderboard, so I'm trying to get the fastest race time out of Single Player and Multiplayer modes no matter what.) I put the conditions below also numbered throughout the statement to understand where the problem is.
If a user completes a SP race only, display the SP race time: (Condition works.)
If a user completes a MP race only, display the MP race time: (Condition works.)
If a user completes both modes with a faster MP race than SP race, show the faster MP race time. (Condition doesn't work.)
If a user completes both modes with a faster SP race than MP race, show the faster SP race time. (Condition doesn't work.)
Code: http://ift.tt/UldW8M
I've tried changing and debugging all of my variables, but both modes will not get the fastest race time. My code always will display the slowest race time with #3 and #4.
Edit:
<?php
// Output the XML
$SP = simplexml_load_string($xml);
$MP = simplexml_load_string($xml1);
var_dump($SP);
echo "<br>";
var_dump($MP);
//I dont know if this line will cause any trouble yet...
$playertime = $world['eventDuration'];
if (isset($SP->worldLeaderboard) && !isset($MP->worldLeaderboard))
{
//we just have SP
$worldboard = $SP;
$mode = 'SP';
}
else if (!isset($SP->worldLeaderboard) && isset($MP->worldLeaderboard))
{
//we just have MP
$worldboard = $MP;
$mode = 'MP';
}
else if( isset($SP->worldLeaderboard) && isset($MP->worldLeaderboard))
{
// we have both
// worldboard ?
// mode ?
$milli = $SP->worldLeaderboard['eventDurationMilliseconds'];
$milli1 = $MP->worldLeaderboard['eventDurationMilliseconds'];
$variable = $SP->worldLeaderboard['eventDuration'];
$variable1 = $MP->worldLeaderboard['eventDuration'];
if($variable < $variable1)
{
$playertime = $variable;
$worldboard = $SP;
$mode = 'SP';
}
else
{
$playertime = $variable1;
$worldboard = $MP;
$mode = 'MP';
}
}
else
{
// we have no XML...
}
?>
*XML:
object(SimpleXMLElement)#3 (1) {
["worldLeaderboard"]=> object(SimpleXMLElement)#5 (2) {
["@attributes"]=> array(11) {
["eventId"]=> string(2) "20"
["eventType"]=> string(1) "2"
["eventMode"]=> string(1) "1"
["eventDurationMilliseconds"]=> string(6) "213622"
["eventDuration"]=> string(11) "0:03:33.622"
["createdDate"]=> string(31) "2014-07-21 00:53:35.0 GMT-00:00"
["createdDateStr"]=> string(10) "2014/07/21"
["personaName"]=> string(14) "GT544T4T34T4T3"
["make"]=> string(15) "CAR_MANU_NISSAN"
["carName"]=> string(17) "CAR_MDL_SILVIAS15"
["rank"]=> string(1) "1"
}
["persona"]=> object(SimpleXMLElement)#6 (1) {
["@attributes"]=> array(5) {
["personaName"]=> string(14) "GT544T4T34T4T3"
["level"]=> string(1) "3"
["image"]=> string(2) "19"
["statusMessage"]=> string(0) ""
["defaultPersona"]=> string(4) "true"
}
}
}
}
object(SimpleXMLElement)#2 (1) {
["worldLeaderboard"]=> object(SimpleXMLElement)#5 (2) {
["@attributes"]=> array(11) {
["eventId"]=> string(2) "20"
["eventType"]=> string(1) "1"
["eventMode"]=> string(1) "1"
["eventDurationMilliseconds"]=> string(6) "226126"
["eventDuration"]=> string(11) "0:03:46.126"
["createdDate"]=> string(25) "2014-07-21 00:43:23.0 GMT"
["createdDateStr"]=> string(10) "2014/07/21"
["personaName"]=> string(14) "GT544T4T34T4T3"
["make"]=> string(15) "CAR_MANU_NISSAN"
["carName"]=> string(17) "CAR_MDL_SILVIAS15"
["rank"]=> string(1) "1"
} ["persona"]=> object(SimpleXMLElement)#6 (1) {
["@attributes"]=> array(5) {
["personaName"]=> string(14) "GT544T4T34T4T3"
["level"]=> string(1) "3"
["image"]=> string(2) "19"
["statusMessage"]=> string(0) ""
["defaultPersona"]=> string(4) "true"
}
}
}
}
No comments:
Post a Comment