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

Help Make This Code

Discussion in 'HTML & JavaScript' started by Empire007, Sep 30, 2013.

  1. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    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
     
  2. ramseo

    ramseo Newbie

    Joined:
    Sep 30, 2013
    Messages:
    19
    Likes Received:
    6
    Location:
    i.imgur.com/lAsiTIO.png
    keep bumping maybe somebody will help you or try searching the codes on stockoverflow
     
  3. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    have spent the whole day there,

     
  4. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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
     
  5. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    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

     
  6. A N K E S H

    A N K E S H Junior Member

    Joined:
    Sep 11, 2012
    Messages:
    110
    Likes Received:
    207
    Occupation:
    Masters
    Location:
    Arthmatic Login unit
  7. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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.
     
  8. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,650
    Likes Received:
    3,494
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
    Hit my pm op, i can do it for you for low $xx :)
     
  9. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    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

     
  10. larrydetuvi

    larrydetuvi Regular Member

    Joined:
    Mar 7, 2011
    Messages:
    249
    Likes Received:
    80
    Can't you use cookies instread of a DB?
     
  11. monk13

    monk13 Power Member

    Joined:
    Jul 10, 2009
    Messages:
    547
    Likes Received:
    268
    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
     
  12. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    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


     
  13. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    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.
     
  14. Empire007

    Empire007 Regular Member

    Joined:
    Jul 22, 2012
    Messages:
    426
    Likes Received:
    67
    Exactly, couldnt have said it better