Home > Programming, Servers & Scripts >

Anyone know a script for this... (11)


12-02-2013 11:32 AM #1 bravenewworld (Member)
Anyone know a script for this...

What script do I need to say something like this..."11 new females have joined in the past hour" with the number constantly increasing by random increments 11 -> 14 -> 15 -> 19 -> 26 -> 31


12-02-2013 12:11 PM #2 cent01 (Member)

http://php.about.com/od/phpfunctions...random_num.htm


12-02-2013 12:26 PM #3 redrummr (Member)

This does not change the number, it only sets a random number on the page load.

OP, you will need to use javascript to randomise the number. PHP can't help you.


12-02-2013 12:31 PM #4 bravenewworld (Member)

Any idea on the javascript code?

Would it look like this <script>whatever the code is</script> new females have joined in the past hour?


12-02-2013 12:50 PM #5 caurmen (Administrator)

I think http://stmforum.com/forum/showthread...r-Your-Landers will do what you need!


12-02-2013 04:21 PM #6 JasperP (Member)

Here ya go

Code:
<!DOCTYPE HTML>
<html>
<head>

<script type="text/javascript">

    // This is in milliseconds
    var delay_seconds = 1000
    var female_count = 11
    
    setInterval(function() {
        // This is maximum number to increment count by
        var increment_max = 5
        
        // Get random number between 1 and increment_max
        var rand_num = Math.floor(Math.random() * increment_max) + 1
        
        // Add random number to current count
        female_count += rand_num
        
        document.getElementById("random_number").innerHTML = female_count
    }, delay_seconds)

</script>

	
</head>

<body>

<span id="random_number">11</span> new females have joined in the past hour 

</body>
</html>


12-06-2013 06:34 PM #7 bravenewworld (Member)

Thanks man


12-08-2013 11:35 AM #8 angry old lady (Member)

why not this?

<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>


02-09-2014 09:10 PM #9 bravenewworld (Member)

@JasperP, how could I decrease the count instead of increase? Also, how can I make sure the count doesn't go below 5? I want to do 100 spots left and have it go down from there.


02-09-2014 09:57 PM #10 hd2010 (Member)

why javascript not php, i prefer everything php


02-09-2014 11:21 PM #11 goscooby (Member)

PHP is only server side ... whatever content is returned to the client browser is what is shown. Javascript can modify the DOM on the client side and update with a timer what is shown to the user.


Home > Programming, Servers & Scripts >