1

The idea: To create a countdown to show days or hours left until some event (no minutes or seconds are required)...

I have MySQL database which stores data used by countdown: id, date & description. I have a PHP file to get it all from database and output it into HTML

How it looks:

HTML Output:

<span>2 Days</span> Until Some Event!

PHP Code:

$result = mysql_query("SELECT * FROM countdowns ORDER BY id DESC",$connect);
while($myrow = mysql_fetch_assoc($result))
{
    echo "<div class=\"countdown\">";
        echo "<span>";
            echo $myrow['date'];
        echo "</span> ";
        echo $myrow['description'];
    echo "</div>";

So I want 'span' to dispaly days OR hours and rest will be description pulled from the database.

The problem: I want it to display ONLY days if hours are greater than 48 or ONLY hours if there are less than 48 hours left.

So it should look like:

5 Days Until Some Event! (There are more than 48 hours left)

OR

5 Hours Until Some Event! (There are obviously less than 48 hours left)

Why I need jQuery for this is because the page on which this countdown will be shown, will be active for days without reloading, so I need it to be dynamic...

I hope you can understand what I mean and probably could help me, thank you very much in advance!

Andrew Badger

2
  • do you have any draft php scripts? what king of answer do you wait? you want smbd to write this all for you? Commented Jun 29, 2011 at 8:29
  • @heximal I have edited my question with PHP code, sorry for not doing it in the first place... Commented Jun 29, 2011 at 8:37

1 Answer 1

1

Maybe you could use a plugin like timeago and change it so that instead of writing the time eladsed from a timestamp it shows the time missing to a timestamp.

EDIT - maybe you don't need to change any part of the code but just set this settings

jQuery.timeago.settings.allowFuture = true;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer, the plugin you have linked looks pretty interesting, I will have a play with it later... Maybe it will work the way I need.
This plugin did everything I needed! Thank you very much Nicola.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.