I'm new to PHP so I was wondering if i could get a question answered.
I'm trying to display 5 random images from a yahoo pipes feed I created.
I'm able to get the 5 random images to display from the feed but I was wondering if there is a way to check the output of each so if the same images appears twice in the output the script is run again until it displays an image not currently being displayed.
Either that or a random output generator that displays 5 images that aren't the same.
This what I have so far.
- Code: Select all
<div id="DCfeeds">
<!-- feed1 PIPE -->
<?php
// Pipes Request
$req = 'http://pipes.yahoo.com/pipes/pipe.run?_id=3a2cd5ebbce8bd263ba0e491e14ad43f&_render=php';
// Make the request
$phpserialized = file_get_contents($req);
// Parse the serialized response
$phparray = unserialize($phpserialized);
// array to hold just the pipe items
$items = $phparray['value']['items'];
// get the total number of items in the array
$items_length = count($items);
// generate a random number between 0 and the end of the items array
$randomIndex = rand(0, $items_length-1); // remember the array starts at 0 so the last item index is the total number of items minus 1
$randomIndex2 = rand(0, $items_length-1);
$randomIndex3 = rand(0, $items_length-1);
$randomIndex4 = rand(0, $items_length-1);
$randomIndex5 = rand(0, $items_length-1);
// get the data we want for the item at $randomIndex
$link = $items[$randomIndex]['y:published']['link'];
$link2 = $items[$randomIndex2]['y:published']['link'];
$link3 = $items[$randomIndex3]['y:published']['link'];
$link4 = $items[$randomIndex4]['y:published']['link'];
$link5 = $items[$randomIndex5]['y:published']['link'];
$thumbnail_url = $items[$randomIndex]['media:thumbnail']['0']['url'];
$thumbnail_url2 = $items[$randomIndex2]['media:thumbnail']['0']['url'];
$thumbnail_url3 = $items[$randomIndex3]['media:thumbnail']['0']['url'];
$thumbnail_url4 = $items[$randomIndex4]['media:thumbnail']['0']['url'];
$thumbnail_url5 = $items[$randomIndex5]['media:thumbnail']['0']['url'];
?>
<h2><a href="">feed1</a></h2>
<div id="DCbar">
</div> <!--DCbar-->
<div id="DCcounter">
</div> <!--DCcounter-->
<div id="DCoutput">
<img src="<?php echo $thumbnail_url; ?>" />
<img src="<?php echo $thumbnail_url2; ?>" />
<img src="<?php echo $thumbnail_url3; ?>" />
<img src="<?php echo $thumbnail_url4; ?>" />
<img src="<?php echo $thumbnail_url5; ?>" />
</div> <!--DCoutput-->
</div> <!--DCfeeds-->


