dimanche 19 novembre 2017

Putting an IF statement inside a foreach and missing out entry

I have an IF statement inside a foreach loop getting data from an XML file. I then want to run through each entry in the XML file and skip putting this into a table if it doesn't meet a certain criteria. The code below is just skipping every entry and it's returning blank with nothing being put in a table.

PHP CODE :

<table width="500" border="0" cellpadding="5">
<tr>
<?php

$xml=simplexml_load_file("movie.xml") or die("Error: Cannot create object");

foreach($xml->children() as $movie) :

 if($xml->sad<=$_GET['happiness']
 && $xml->agitated<=$_GET['calmness']
 && $xml->tired<=$_GET['tired']
 && $xml->scared<=$_GET['scared'] )
 {?>
   <td align="center" valign="center">
   <img src="<?php echo $movie->path?>" width="150px" alt="<?php echo $movie->descrip?>"/>
   <br />
   <?php echo $movie->name ?>
   </td>
<?php } endforeach; ?>
</tr>
</table>

XML CODE:

<movie>
        <name>Harry Potter</name>
        <path>images/harry.jpg</path>
        <sad>50</sad>
        <agitated>25</agitated>
        <tired>50</tired>
        <scared>75</scared>
</movie>

Aucun commentaire:

Enregistrer un commentaire