You have two loops inside each other.
One counts from 0 to 5:
for($i = 0; $i < 5; )
// some code
$i++; // this could just be in the for(), by the way
Inside that, you have some code which does the same thing every time, ignoring the counter. That contains a loop which looks at each video in turn:
foreach ($sxml->entry as $entry) {
But before it has a chance to look at anything other than the first entry, you break out of the inner loop:
break;
You only need one loop or the other.
Using the counter approach, you could use $i
to reference a particular entry in the XML:
$sxml = simplexml_load_file($feedURL);
for($i = 0; $i < 5; $i++) {
$entry = $sxml->entry[$i];
// display a video
}
Beware that this will fail if there are ever less than 5 entries; you could fix that by testing isset($sxml->entry[$i])
.
Using the foreach
loop, you could count how many videos you've echoed and break
when you get to the 5th:
$sxml = simplexml_load_file($feedURL);
$i = 0;
foreach ($sxml->entry as $entry) {
$i++;
// display a video
if ( $i == 5 ) {
break;
}
}