1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help Me Make This Code

Discussion in 'PHP & Perl' started by Empire007, Feb 6, 2014.

  1. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    Hi, yall. Please i need help making a code. if this kind of thing is possible, would like to be able to get it

    I need a code that all it does it to add numbers to an original number at diffrent time intervals starting from the number you input.

    Lets say you have 28002 downloads, and you want it that in per hour it adds 7, 5, 3, 2, 4, 5 then starts over again at 7, 5, 3, 2, 4, 5 and continues. it does that

    So it then happens like this

    1st Hour: 28002
    2nd Hour: 28009
    3rd Hour: 28014
    4th Hour: 28017
    5th Hour: 28019
    6th Hour: 28023
    7th Hour: 28028

    Then starts adding again

    8th hour: 28035

    then forever continuous
     
  2. macdonjo3

    macdonjo3 Jr. VIP Jr. VIP Premium Member

    Joined:
    Nov 8, 2009
    Messages:
    5,564
    Likes Received:
    4,317
    Location:
    Toronto
    Home Page:
    What's your code so far?
     
  3. TehEpidemick

    TehEpidemick BANNED BANNED

    Joined:
    Oct 31, 2011
    Messages:
    778
    Likes Received:
    181
    This isn't that hard if I understand correctly. Have you started yet?
     
  4. Automation247

    Automation247 Regular Member

    Joined:
    Jan 21, 2014
    Messages:
    403
    Likes Received:
    126
    Occupation:
    Making some $$$
    Location:
    SPAMMING 24/7 FROM SOMEWHERE IN EUROPE
    Home Page:
    It's pretty easy to code really.. try to find some info in Google.
     
  5. cyrix

    cyrix Junior Member

    Joined:
    Sep 19, 2008
    Messages:
    179
    Likes Received:
    61
    Occupation:
    Full Time Internet Marketer\Developer
    Location:
    United States
    What language are you trying to code this in? web based or desktop based?
     
  6. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    My code would goes something like this in php.

    Code:
    <?php
    date_default_timezone_set('America/New_York');
    $download = 28000;
    
    $add = [7, 5, 3, 2, 4, 5];
    $cycletotal = 26; // 7+5+3+2+4+5
    $time1 = time();
    $time2 = mktime(0,0,0,2,6,2014); // a starting point
    
    $hourdiff = floor(($time1 - $time2) / 3600);
    $cyclediff =  floor($hourdiff / 6);
    $idx = (($hourdiff-1) % 6); // 3600 seconds in hour
    
    $sum = 0;
    for ($i = 0; $i <= $idx; $i++) {
    	$sum = $sum + $add[$i];
    }
    
    echo "<br/>";
    echo 28000 + ($cyclediff * $cycletotal) + $sum;
    echo "<br/>";
    
    ?>
    
     
    • Thanks Thanks x 1
  7. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    thanks i will check this out. i want to use it on blogger / html. am not really good at coding yet. thats y i couldnt make it. let me test this out. thanks
     
  8. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    it didnt work on html. just saw u mentioned php. do u know a way i can make it work on html, blogger, etc?

     
  9. nshunz

    nshunz Junior Member

    Joined:
    Nov 10, 2013
    Messages:
    106
    Likes Received:
    15
    You'll need apache server to make it work. Install xampp and then run it.
     
  10. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    this means people without xampp installed on thier systems wouldnt be able to see it?

     
  11. nshunz

    nshunz Junior Member

    Joined:
    Nov 10, 2013
    Messages:
    106
    Likes Received:
    15
    No, xampp is hosted on your system so only you can check its working.

    For everyone to see put the code on a server running apache.
     
  12. divok

    divok Senior Member

    Joined:
    Jul 21, 2010
    Messages:
    1,015
    Likes Received:
    634
    Location:
    http://twitter.com/divok
    have you coded it ? First show your code, then we will find the problem . But it looks you don't even know
    Don't expect to be spoon-fed .
     
  13. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    Sorry, missed your reply.

    I'll try to code it in javascript coming mon.
    It shouldn't be too hard since the logic is already there.

    But, you notice you post in php forum? :)
     
  14. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    As mentioned previously, the javascrip code is as below

    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    		
    		function testonload() {
    		    var add = [7, 5, 3, 2, 4, 5];
    			var cycletotal = 26; // 7+5+3+2+4+5
    			var time1 = new Date();
    			var time2 = new Date(2014, 0, 1, 0, 0); // a starting point
    			var hourdiff = Math.floor((time1-time2) / (1000 * 3600));
    			var cyclediff = Math.floor(hourdiff / 6); //	$cyclediff =  floor($hourdiff / 6);
    			var idx = (hourdiff-1) % 6; // $idx = (($hourdiff-1) % 6); // 3600 seconds in hour
    
    			var sum = 0; 
    			
    			for (var i = 0; i <= idx; i++) {
    				sum = sum + add[i];
    			}
    			
    			alert(28000 + (cyclediff * cycletotal) + sum );
    		}
    
    		</script>		
    	</head>
     
    	<body>
    		<script>
    			testonload();
    		</script>
    	</body>
    </html>
    
     
    • Thanks Thanks x 1
  15. Jeff Bezos

    Jeff Bezos Junior Member

    Joined:
    Jan 11, 2014
    Messages:
    178
    Likes Received:
    81
    WOW! Why are you guys shoving the spoon down this blokes throat? He doesn't even know how php works... You're not helping anyone by writing code and pasting it here for them to copy and paste.
     
  16. Amsterdammer

    Amsterdammer Power Member

    Joined:
    Aug 9, 2011
    Messages:
    515
    Likes Received:
    563
    People help each other here. :)
    OP will soon find out that JS will not work for what he wants to do, he should use PHP. Also, the script given needs some more work and this just might get him interested in coding. (The script is generic at this point.)

    @OP, JS is client side, it means that every time you refresh the page the cycle starts from scratch. PHP is server side and can generate the HTML you see on your screen, it can do a whole lot of other things too. If you want your fake download counter to stick, use PHP and your database. :) Your task is so easy it could be a nice introduction to coding.
     
    • Thanks Thanks x 2
  17. nastybasti

    nastybasti Newbie

    Joined:
    Jan 21, 2014
    Messages:
    26
    Likes Received:
    8
    Occupation:
    fullstack web developer
    Location:
    USA
    If you are running this type of code in Javascript then you always have to have a browser window open. If you are doing it via php or asp or other server side then you need to really expand it quite a bit.

    The approach i would take is to create a jobs or que table in database. And then each time the number is increased then a new job is created in the db. That job has a due date which is RANDOM, the job can also hold the next number.

    Then setup a cron job to run a job.php file which checks to see if there are any overdue jobs to perform. Thats the only way i can think of running something like this without having to have a browser open 24/7.

    If you dont want to write web based then you can setup a cron job for a bash script to do this or perl or ruby. But it really dpends on your purposes.
     
    • Thanks Thanks x 1
  18. Jeff Bezos

    Jeff Bezos Junior Member

    Joined:
    Jan 11, 2014
    Messages:
    178
    Likes Received:
    81
    You could also use JavaScript with innerHTML of a div.
     
    • Thanks Thanks x 1
  19. bluehatface

    bluehatface Regular Member

    Joined:
    Oct 19, 2013
    Messages:
    232
    Likes Received:
    98
    Location:
    Here
    Long story short: you can't do it in just blogger. You're gonna have to host your own site, or fetch the data hosted somewhere else.
     
  20. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    everyone here saying you need php and a database should look at the code from mypmmail and analyze what it's doing...

    the javascript code works fine, replace the alert with document.write and you can paste it direct into your html
    Code:
    <script>
    var add = [7, 5, 3, 2, 4, 5];
    var cycletotal = 26; // 7+5+3+2+4+5
    var time1 = new Date();
    var time2 = new Date(2014, 0, 1, 0, 0); // a starting point
    var hourdiff = Math.floor((time1-time2) / (1000 * 3600));
    var cyclediff = Math.floor(hourdiff / 6); //    $cyclediff =  floor($hourdiff / 6);
    var idx = (hourdiff-1) % 6; // $idx = (($hourdiff-1) % 6); // 3600 seconds in hour
    
    var sum = 0;
    
    for (var i = 0; i <= idx; i++) {
            sum = sum + add[i];
    }
    
    document.write(28000 + (cyclediff * cycletotal) + sum );
    </script>
    
     
    • Thanks Thanks x 2