Help Me Make This Code

Empire007

Power Member
Joined
Jul 22, 2012
Messages
519
Reaction score
85
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
 
What's your code so far?
 
This isn't that hard if I understand correctly. Have you started yet?
 
It's pretty easy to code really.. try to find some info in Google.
 
What language are you trying to code this in? web based or desktop based?
 
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 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
 
it didnt work on html. just saw u mentioned php. do u know a way i can make it work on html, blogger, etc?

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/>";

?>
 
this means people without xampp installed on thier systems wouldnt be able to see it?

You'll need apache server to make it work. Install xampp and then run it.
 
this means people without xampp installed on thier systems wouldnt be able to see it?

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.
 
have you coded it ? First show your code, then we will find the problem . But it looks you don't even know
it didnt work on html. just saw u mentioned php. do u know a way i can make it work on html, blogger, etc?

Don't expect to be spoon-fed .
 
it didnt work on html. just saw u mentioned php. do u know a way i can make it work on html, blogger, etc?

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? :)
 
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>
 
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.
 
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.

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.
 
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.
 
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.
 
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>
 
Back
Top