I'm working with an XML product list that displays a list of around 20 products, and within each <item> there is a <description> and then one <bullet> for each. Here's an example:
I'm using a foreach loop with SimpleXML to pull in the product data, and all individual tags such as <image> and <title> are working fine.
My issue is that it is only parsing the first <bullet> for each product and not all of them. To fix this I attempted to add a for loop which targets all nested items within the <description> tag and outputs however many there are. But it's now giving me the first <bullet> of the first item on the XML file and putting it under every product, instead of showing multiple bullets for each respective product, which is what I want.
I'll post my script and hopefully someone will be able to point out where I'm going wrong.
<?php
$items = simplexml_load_file('http://www.itclear.com/BestSellers.xml');
foreach ($items->channel->item as $item):
$title=$item->title;
$image=$item->image;
$price=$item->price;
$description=$item->description;
$link=$item->link;
echo '
<div class="xsmall-12 medium-6 large-4 columns product">
<div class="inner">
<div class="product-image">
<img class="product-image" src="',$image,'"/>
</div>
<h2 class="product-title"><strong>',$title,'</strong></h2>
<ul>';
$bullets = $items->channel->item->description;
for($i=0;$i<=$bullets;$i++){
echo '<li>',$bullets[$i]->bullet,'</li>';
}
echo'
</ul><span class="product-price">£',$price,'</span>
<a class="product-link" href="',$link,'" target="_blank" title="Visit ITC Sales to buy ',$title,'">View Deal <i class="fa fa-angle-right" aria-hidden="true"></i></a>
</div>
</div>';
endforeach;
?>