What am I doing wrong? Block needs to be put into "Edit Mode" before updating dynamic content

Permalink
I have a block which I am trying to create dynamic content in.

Every time the page loads I am selecting another image and attempting to display this.

In a normal PHP file this would work as I load a random file each time, I had thought that the code below was loaded on each instance of the block view? but unless I go in and edit the content and press Update nothing changes.

I have no cache turned on(cleared also now) but am unable to get a different image to load?

can anyone point out any tips or pointer on how I can achieve this?
[I have tried running the random code on render/on_page_view/view from within the controller but none seem to do what I want ]

Do I need to move the calculations away from the view and back into the controller?

<?php
$array = array(1,4,5); //image positions in the db I would like to check
shuffle($array);
$rand = rand(1,3)-1;//index of array
$imageNo = $array[$rand];
//should this be done in the controller?
$found=false;
   foreach($array as $a=>$v){
      if (!empty(${'field_'.$v.'_image'})){
         $imageNo = $v;
      }
   }
?>
   <?php 
   for($i=0;$i<3;$i++){

TheRealSean
 
olliephillips replied on at Permalink Reply
olliephillips
Your shuffle routine is enough to make the images random. If you pull the same index of that array each time $array[0], the fact that shuffle reorders your array, means you'll be getting a random image number.

Not saying that is why you're getting the same image, but rand has caused me problems in the past - if I understand what you are trying to achieve correctly you don't need to use rand.

Hope that helps
TheRealSean replied on at Permalink Reply
TheRealSean
Got you, I have removed the random call.

But you where correct it does not affect the image actually loading,
unless I go back into edit mode.

I will have a go and try to move the calculations to the controller and see if that makes a difference?