Need help with basic PHP scripting.

Zoekban

Registered Member
Joined
Apr 23, 2013
Messages
63
Reaction score
15
I've made recently a script for showing random pictures, The thing is that i want the script to show Random picture every specific time , like in 5 minutes, in 15 and in 30,
How can it be done, And what do i need to add to my script to improve the script to be working by random timing?

The script is being used in WordPress with the "allow php in post" plugin.

The script is -


$total = "2";
$file_type = ".jpg";
$image_folder = "(images source)";
$start = "1";


$random = mt_rand($start, $total);


$image_name = $random . $file_type;


echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";


Thanks from ahead, And waiting for a reply and help.
Thank you.
 
You'd be better served by using jQuery for something like this:
Code:
<img id="thisImg" alt="img" src="img0.png"/>


<script type="text/javascript">
    $(function(){

        var imgArray=new Array();
        imgArray[0]="img1.png";
        imgArray[1]="img2.png";
        imgArray[2]="img3.png";
        imgArray[3]="img0.png";

        rand = Math.round(Math.random()*(300000-3600000))+3600000; // generate new time (between 5min and 1hour)

        window.setInterval(function(){
            randImg = imgArray[Math.floor(Math.random()*imgArray.length)];
            $('#thisImg').attr('src',randImg);
        },rand);        
    });
</script>
 
Last edited:
And how I can arrange this script with the one I have right now?
I'm sorry for my questions, But I'ts all new for me, And i will be grateful for all the help.
 
Can you explain a little more?

Do you want to just include this in one post, and have the image constantly change, or do you want that, every 5 minutes, your script posts a new blog post with a new image?
 
The first script, Changes the image randomly every time you refresh the page.
I want to make that, To be changed to randomly image, But not on every refresh, But every couple of minutes, for example every 5 minutes
 
Back
Top