Help Make This Code

Empire007

Power Member
Joined
Jul 22, 2012
Messages
519
Reaction score
85
hey guys, please i need a code that would start from 0 and begin increasing

if i make a post i***iately it starts

e.g. Total Downloads: 0, then every seconds it increases by 4 or so

after 10 seconds, i refresh then i would now see

Total Downloads: 40.... it would be going up if you refresh the page, and i would need to be able to use it on multiple pages of my websites and if i make a post, they would start from 0 again
 
keep bumping maybe somebody will help you or try searching the codes on stockoverflow
 
Not entirely clear...but I assume you have a downloads site and you're trying to artificially inflate the download counts?

This pseudocode would do what you need:
Code:
fetch download posts
loop through download posts {
    get post download count
    increase download count by 4
    store new count in database
}
Then you'd make a cron job to run every x seconds and execute that script.

In PHP, it's roughly:
PHP:
$dbLink = mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($dbLink)); // connect to database
$fetchDownloadPosts = $dbLink->query("SELECT post_id,post_downloads FROM posts"); // fetch all the software posts

while ($downloadPost = mysqli_fetch_array($fetchDownloadPosts)) { // loop through software posts
    $postId = $downloadPost["post_id"]; // read database post ID
    $downloadCount = $downloadPost["post_downloads"] + 4; // calculate new inflated download count
    $dbLink->query("UPDATE posts SET post_downloads='" . $downloadCount . "' WHERE post_id='" . $postId . "'"); // store download count in database
}

mysqli_close($dbLink); // end database connection
 
Yes, i have a downloads website but its on blogger. so i would need something like a html code, this would work on something with database like wordpress, but now blogger i cant do a cron job there, thanks for your suggestion thou :), but its for blogger sorry i didnt state it earlier

Not entirely clear...but I assume you have a downloads site and you're trying to artificially inflate the download counts?

This pseudocode would do what you need:
Code:
fetch download posts
loop through download posts {
    get post download count
    increase download count by 4
    store new count in database
}
Then you'd make a cron job to run every x seconds and execute that script.

In PHP, it's roughly:
PHP:
$dbLink = mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($dbLink)); // connect to database
$fetchDownloadPosts = $dbLink->query("SELECT post_id,post_downloads FROM posts"); // fetch all the software posts

while ($downloadPost = mysqli_fetch_array($fetchDownloadPosts)) { // loop through software posts
    $postId = $downloadPost["post_id"]; // read database post ID
    $downloadCount = $downloadPost["post_downloads"] + 4; // calculate new inflated download count
    $dbLink->query("UPDATE posts SET post_downloads='" . $downloadCount . "' WHERE post_id='" . $postId . "'"); // store download count in database
}

mysqli_close($dbLink); // end database connection
 
Yes, i have a downloads website but its on blogger. so i would need something like a html code, this would work on something with database like wordpress, but now blogger i cant do a cron job there, thanks for your suggestion thou :), but its for blogger sorry i didnt state it earlier
Is there a database somewhere that stores download data? Because I'm not sure how that would be possible with Blogger. Your post could contain something like, "Downloads: 0", yes, but the only way to manipulate that as far as on-page is through javascript, and these changes won't be saved. So if your user loads the page, you could have a javascript code manipulate the download count in real-time to make it appear as though people are downloading the file while they are on the page, but if the user were to come back later, it would be 0 again and the process would restart.

You could create an off-site database, reference it with AJAX, and use javascript to update the download count. The same PHP code I provided would be used for your off-site database on a separate host, and then your Blogger page could have javascript code that loads an off-site page, fetches the download count for the particular post, and updates it accordingly in the HTML. You could use a free off-site host for this. All you need is a database and the ability to run PHP.

Otherwise, without a database or a way to store download info (even an off-site text file or CSV would work), then the only way to manipulate the download count is with javascript, but the download data wouldn't be saved for future visits for other users.
 
thanks for your careful explaination, a not too good with codes and stuff, but your explanation looks pretty good to me. So i would try to see if i can do it as you said. thanks alot... will post if i have any problems

Is there a database somewhere that stores download data? Because I'm not sure how that would be possible with Blogger. Your post could contain something like, "Downloads: 0", yes, but the only way to manipulate that as far as on-page is through javascript, and these changes won't be saved. So if your user loads the page, you could have a javascript code manipulate the download count in real-time to make it appear as though people are downloading the file while they are on the page, but if the user were to come back later, it would be 0 again and the process would restart.

You could create an off-site database, reference it with AJAX, and use javascript to update the download count. The same PHP code I provided would be used for your off-site database on a separate host, and then your Blogger page could have javascript code that loads an off-site page, fetches the download count for the particular post, and updates it accordingly in the HTML. You could use a free off-site host for this. All you need is a database and the ability to run PHP.

Otherwise, without a database or a way to store download info (even an off-site text file or CSV would work), then the only way to manipulate the download count is with javascript, but the download data wouldn't be saved for future visits for other users.
 
a smarter way to do this would be with php, ajax or asp and each time the page gets loaded it increments the new value by a random number between x-y
that way you don't end up with a ridiculous number by the end of day 4
 
true, i saw it on www.naijaloaded.com first and it looks like a fake script but its a forum, so its using a database. like he explained earlier


a smarter way to do this would be with php, ajax or asp and each time the page gets loaded it increments the new value by a random number between x-y
that way you don't end up with a ridiculous number by the end of day 4
 
Can't you use cookies instread of a DB?
Cookies will only apply to each individual user. You could create a javascript cookie, store a random int, and then increment this int by x value whenever the user comes back to the page, but this incrementation only applies to each individual user. If another user hits the page later, they'll be back at 0 downloads while the incrementation begins on their browser and is stored in the cookies.

This, however, relies on the user visiting multiple times for some reason. And it will only be active while the user is on the site. OP wants the download count to update globally for all users regardless if there are any visitors on the site, and cookies will only apply to each individual user and can only be manipulated while on the site.
 
Exactly, couldnt have said it better

Cookies will only apply to each individual user. You could create a javascript cookie, store a random int, and then increment this int by x value whenever the user comes back to the page, but this incrementation only applies to each individual user. If another user hits the page later, they'll be back at 0 downloads while the incrementation begins on their browser and is stored in the cookies.

This, however, relies on the user visiting multiple times for some reason. And it will only be active while the user is on the site. OP wants the download count to update globally for all users regardless if there are any visitors on the site, and cookies will only apply to each individual user and can only be manipulated while on the site.
 
Back
Top