Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

echo a message on reaching 0 on jquery countdown timer?

$
0
0

I am at my wits end with this as i really need to move on and I'm stuck with such a simple task! any help would be greatly appreciated.

what I am trying to do is to echo a Times Up message once the countdown reaches 0.

I know the plugin has an onExpiry Function but I don't want to use javascript. I want to use PHP so the users can't disable it.

This is my full code:

<?php 
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php date_default_timezone_set('GMT'); ?>
<?php
session_start();
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
include "config/connect.php";
$dynamicList = "";
$sql = "SELECT * FROM item ORDER BY id ";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query); // count the output amount
if ($productCount > 0) {
    while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
             $id = $row["id"];
             $product_name = $row["product_name"];
             $date_added = date("Y, m, d", strtotime($row["date_added"]));
             $end_date = date("Y, m, j, G, i, s", strtotime($row["end_date"]));
             $price = $row["price"];
             $dynamicList .= '<div>' . $end_date . '
      </div>';
    }
} else {
    $dynamicList = "No Records";
}
?>
<?php
$tmp_date = explode(', ', $end_date);
$tmp_date[1] = $tmp_date[1] - 1;
$end_date = implode(', ', $tmp_date);
?>
<?php
$date = $end_date;
$exp_date = date("Y, m, j, G, i, s", strtotime($date));
$now = time();

if ($now < $exp_date ) {
?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>

    <noscript>
        <h3>JavaScript is disabled!
        Please enable JavaScript in your web browser!</h3>

        <style type="text/css">
            #defaultCountdown { display:none; }
        </style>
    </noscript>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>jQuery Countdown</title>
    <link rel="stylesheet" href="jquery.countdown.css">
    <style type="text/css">
    #defaultCountdown { width: 240px; height: 45px; }
    </style>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.countdown.js"></script>

    <script type="text/javascript">

     $(document).ready(function () {
        $('#defaultCountdown').countdown({
            until: new Date(<?php echo $end_date ?>),
            compact: true,
            onTick: warnUser
        });
    });



    </script>
    </head>
    <body>
    <?php
    } else {
        echo "Times Up";
    }
    ?>

    <div id="defaultCountdown" style="font-family:Verdana, Geneva, sans-serif;"></div>

    <?php
    } else {
        echo "Times Up";
    }
    ?>
    </body>
    </html>

Currently I am using the code above but all i get is the (Times Up) message without anything else on the page and this is when the timer has hours to end but when i remove these lines:

<?php
$date = $end_date;
$exp_date = date("Y, m, j, G, i, s", strtotime($date));
$now = time();

if ($now < $exp_date ) {
?>

and

<?php
} else {
    echo "Times Up";
}
?>

the timer shows up and starts working again. I need to find a way to show/display the Times Up message as soon as the counter hits 0 and I need to do it via PHP for security reasons.

Thanks in advance.


Viewing all articles
Browse latest Browse all 13200

Trending Articles