mercredi 4 février 2015

If statement only uses last data set of xml PHP

My If statement only works if the conditions are met in the last data set of the XML data. If the conditions are met before the last entry it does not recognize.


Here is the XML data



<PaymentsByMonthYear xmlns="server" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:schemaLocation="http://ift.tt/16zLkQb" total="4">
<Payment>
<Id>51180698</Id>
<Date>2015/02/02 15:23:27</Date>
<To>Solo</To>
<From>Jon</From>
<Amount>1000.00</Amount>
</Payment>
<Payment>
<Id>51182828</Id>
<Date>2015/02/02 16:57:44</Date>
<To>Solo</To>
<From>lj440</From>
<Amount>100.00</Amount>
</Payment>
<Payment>
<Id>51192472</Id>
<Date>2015/02/02 21:28:25</Date>
<To>SoloBanner</To>
<From>lj440</From>
<Amount>5000.00</Amount>
<Reason>Group payment</Reason>
</Payment>
<Payment>
<Id>51234023</Id>
<Date>2015/02/04 06:00:55</Date>
<To>Bob</To>
<From>SoloBanner</From>
<Amount>5100.00</Amount>
</PaymentsByMonthYear>


Here is the Code I have, it works as long as the last Payment meets the If otherwise it returns "no"



<?php
//Define Username
$user = "lj440";

//Connect to Server
$link1 = "data.xml";
$xml1 = simplexml_load_file($link1) or die("Error: Cannot create object");

//Gather Fields
foreach($xml1->children() as $info1)
{
$from = $info1->From;
$date = $info1->Date;
$amount = $info1->Amount;
}

//Create If Statement
if (($user == $from) AND (strtotime($date) > strtotime("1 month ago")) AND ($amount >= "5000.00"))
{
echo "yes";
}

else
{
echo "no";
}
?>

Aucun commentaire:

Enregistrer un commentaire