I am using simplexml to get the data from an xml I have 3 conditions the category must be jazz the package must be best and the date must be today. That one is sorted out my problem is echoing the title since field that has the ad title moves depending on the ad.
here is a sample of the xml
<product>
<export>
<ad>
<category>
<name>Jazz</name>
</category>
<package>
<name>Good</name>
<start_date>2018-04-18</start_date>
<adcopy>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nec consequat ante. Aenean suscipit imperdiet velit, sed congue felis congue vel. Maecenas non leo at tortor ornare iaculis.</adcopy>
</package>
</ad>
<fields>
<field>
<name>Color</name>
<value>white/blue</value>
</field>
<field>
<name>AdTitle</name>
<value>This is the Title of my 1st item</value>
</field>
<field>
<name>Make</name>
<value>Plastic</value>
</field>
</fields>
</export>
<export>
<ad>
<category>
<name>RNB</name>
</category>
<package>
<name>Good</name>
<start_date>2018-04-17</start_date>
<adcopy>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nec consequat ante. Aenean suscipit imperdiet velit, sed congue felis congue vel. Maecenas non leo at tortor ornare iaculis.</adcopy>
</package>
</ad>
<fields>
<field>
<name>AdTitle</name>
<value>This is the Title of my 2nd item</value>
</field>
<field>
<name>Color</name>
<value>white/blue</value>
</field>
<field>
<name>Make</name>
<value>Plastic</value>
</field>
</fields>
</export>
</product>
And here is the script
foreach ($data->export as $item)
{
if ($item->ad->category->name == 'Jazz' && $item->ad->package->name == 'Good' && $item->ad->package->start_date == $currentday)
{
echo "Title: " . $item->fields->field->value . "<br>";
echo "Description: " . $item->ad->package->adcopy->value . "<br>";
echo "Date: " . $item->ad->package->start_date . "<br>";
}
}
How can I do this? if the field has a name of AdTitle, use that field and show the field->value (which is the title of the ad)
Please help
I tried adding below but it's not working
echo "Issue" . (($item->fields->field->name == 'AdTitle') ? $item->fields->field->value :'')."<br>";
I was able to make it work with below
{
foreach ($item->fields->field as $field)
{
if ($field->name == 'AdTitle')
{
echo "Title: " . $field->value . "<br>";