hey_suburbia Posted February 22, 2010 Share Posted February 22, 2010 Here is a snippet of code I have to populate images and use glider.js to power the image viewer, but I need to make each image random... Any thoughts? Code: <?php foreach ($videos as $video): $video_count++; if ($video->header=="") $play="true"; else $play="false"; ?> <div class="video-list-item"> <a href="javascript:switchHeader('<?=$video->text1?>','<?=$video->file?>','<?=$video->header?>','<?=$video->link?>',<?=$play?>,true)"> <img style='float:left;' src="<?=$this->baseurl?>/images/videos/<?=$video->thumbnail?>"> </a> <div class='wrapper'> <h3><a href="javascript:switchHeader('<?=$video->text1?>','<?=$video->file?>','<?=$video->header?>','<?=$video->link?>',<?=$play?>,true)"><?=$video->text1?></a></h3> <p class='black' ><?=$video->text2?></p> <p style='font-weight: normal' class='black' ><?=$video->text3?></p> </div> <a href="javascript:switchHeader('<?=$video->text1?>','<?=$video->file?>','<?=$video->header?>','<?=$video->link?>',<?=$play?>,true)">> VIEW</a> </div> <?php if ($video_count%3==0 && count($videos)!=$video_count) print "</li><li>"; ?> <?php endforeach; ?></li> Site for reference (The images in the yellow bar): http://www.nhsonline.org/ Link to comment https://forums.phpfreaks.com/topic/192965-random-image-via-php/ Share on other sites More sharing options...
teamatomic Posted February 22, 2010 Share Posted February 22, 2010 shuffle($array) $j=count($array) for($i;$i>$j;$i++) $pic=array_pop($array) edit: or right before you start your foreach just shuffle($videos) HTH Teamtomic Link to comment https://forums.phpfreaks.com/topic/192965-random-image-via-php/#findComment-1016253 Share on other sites More sharing options...
hey_suburbia Posted February 22, 2010 Author Share Posted February 22, 2010 Thanks, but when I did this: <?php shuffle($videos) foreach ($videos as $video): $video_count++; if ($video->header=="") $play="true"; else $play="false"; ?> I got this: Parse error: syntax error, unexpected T_FOREACH in /nfs/c04/h03/mnt/65395/domains/nhsonline.org/html/templates/nhs/glider.php on line 10 Link to comment https://forums.phpfreaks.com/topic/192965-random-image-via-php/#findComment-1016264 Share on other sites More sharing options...
hey_suburbia Posted February 22, 2010 Author Share Posted February 22, 2010 Sorry about the post above that was regarding a missing ";", this is the error I'm getting: Warning: shuffle() expects parameter 1 to be array, object given in /nfs/c04/h03/mnt/65395/domains/nhsonline.org/html/templates/nhs/glider.php on line 9 Link to comment https://forums.phpfreaks.com/topic/192965-random-image-via-php/#findComment-1016266 Share on other sites More sharing options...
teamatomic Posted February 22, 2010 Share Posted February 22, 2010 If $videos is not an array how does a foreach not generate an error?? HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192965-random-image-via-php/#findComment-1016480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.