Search the Community
Showing results for tags 'getrandom()'.
-
Hey, I would like to give me your help. In a project i am working on i am trying to build a slot machine. I am stuck at the point where everytime i click the button, so the reels will spin, i want it to give me a number of random children of a parent. Therefore i used getRandom(3), which is called with an onclick event, and does what it does in <script> tags in the php file. The problem is that it produces 3 random pages only one time. I want it everytime i click the button to find me new random children. So this is the code where is tries to Get the Random children: <script> function fillfirst(){ <?php $i=0; foreach ($get_md->children->getRandom(3) as $md) // here i take 3 random children of parent page { if($i==0){$a=$md->image->url;} elseif($i==1){$b=$md->image->url;} // here i put each child's image a else{$c=$md->image->url;} $i++; } ?> newreels = ['<?php echo $a;?>','<?php echo $b;?>','<?php echo $c;?>']; // here is the reel with the url of the images i want to have // but only at one specific click. Every new click i want the getRandom() // to give me new random children. document.getElementById("freel").innerHTML= '<div><img src="' + newreels.join('"></img><img src="') + '"></img></div><div><img src="' + newreels.join('"></img><img src="') + '"></img></div>' return newreels; } </script> And here is the code where it is called from (inside the html): <button class="w3-button w3-hover-yellow" onclick="fillfirst();">Main</button> If anyone has an idea it would be really helpful.