Random image check.

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Tue Apr 05, 2011 7:26 pm

Cool.

So, you're almost there.

simply create an array to hold your five variables..

Code: Select all

// grab your pictures from yahoo here..

//--->

$need = 5; // change it on the fly if you want..  
while (count($array) <= $need) { // since the count of array is less than or equal to the need..
  $random = rand(0,($items_length - 1)); // pick the random number between 0 and max items - 1
  if (!in_array($random,$array)) {  // if our random number isn't in our storage array.. 
    $array[]=$random; // stuff it! Now it is! (count goes up on next cycle.. when it reaches $need, it quits.
  }
}

//wrap your div's around this..
foreach($array as $key => $value) { //cycle through the array to create your 5 links, dynamically. 
   echo '<img src="'.$items[$value]['media:thumbnail']['0']['url'].'" border="0">';
}
//close your divs around this..
 

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest