PHP Countdown Items Remaining Code??

6 replies
I'm looking for a script that will display a number and drop it down 1 by 1 until its down to 1, for the purpose of simulating the number of available items remaining. It would be more realistic if the number didn't countdown at a consistent interval, but was a bit random.

I've done a lot of searching, but all I could find was countdowns to dates. Does anyone have a script for this that they would be willing to share?

Thanks.
#code #countdown #items #php #remaining
  • Profile picture of the author michael_gourlay
    Do you want it to count down while the person is looking at the page (ie they see it going down)? If so, javascript may be a better option than PHP.
    {{ DiscussionBoard.errors[3349354].message }}
    • {{ DiscussionBoard.errors[3349410].message }}
      • Profile picture of the author magicink
        Without page reload.
        {{ DiscussionBoard.errors[3352654].message }}
        • Profile picture of the author theIMgeek
          What I would do...

          Run a program that randomly selects a number from 1 to 5 every x seconds. If it picked 1, then drop the quantity, otherwise, keep it the same.

          That way it would change in a truly random way.

          Now, if you do this in straight-up javascript (which is required to see the changes in "real-time") there is the problem that your sham of an inventory would be revealed if a person peeks at the page source code. (all the javascript would be exposed)

          If you want to be more discrete you would need to run the random function via AJAX so the processing is done "secretly" with PHP or something.

          -Ryan
          Signature
          FREE WSO: Protect and Automatically Deliver Your Digital Products

          Ask the Internet Marketing Geek
          <-- Happy to help with technical challenges
          MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
          {{ DiscussionBoard.errors[3353024].message }}
          • Profile picture of the author magicink
            It's funny cause I was thinking the same thing. Guess its a pretty basic script.

            I'm not too worried about people peeking. If anything I'd be more worried about someone hitting refresh and seeing it jump right back to the initial inventory count, but its PPV so whatever.
            {{ DiscussionBoard.errors[3354539].message }}
  • Profile picture of the author Damien Roche
    You could use sessions to maintain consistency between page refreshes. It is very simple stuff - you could also use AJAX which would completely avoid people from peeking. However, I do think that's a little paranoid
    Signature
    >> Seasoned Web Developer (CSS, JavaScript, PHP, Ruby) <<
    Available for Fixed Fee Projects and Hourly ($40/hr)
    {{ DiscussionBoard.errors[3355045].message }}

Trending Topics