开发者

SQL Count Down Timer

开发者 https://www.devze.com 2023-03-16 10:21 出处:网络
I\'m creating my own penny auction script. I\'m trying to get the countdown timer to work. Since the div refreshes every second anyway, I don\'t need to use a jquery timer I can just go by the time of

I'm creating my own penny auction script. I'm trying to get the countdown timer to work. Since the div refreshes every second anyway, I don't need to use a jquery timer I can just go by the time of the last bid.

I'm able to get the time of the last bid using the SQL call

$strFind="SELECT * FROM penny_bids WHERE `pennyid`=\"$pid\" ORDER BY id DESC LIMIT 1";
$result=mysql_query($strFind) or die(mysql_erro开发者_运维问答r());
$row=mysql_fetch_array($result);
$memname=$row['memname'];
$btime=$row['time'];

I thought the current time minus the btime would give me the time in seconds but it doesn't.

$time=time()-$btime;

gets me the time stamp. 

How can I get it to get me the only 30 digits? Counting down. So each time the div refreshes it will be 29, 28, etc.


When you get dates and times out of MySQL they'll typically come in YYYY-MM-DD HH:MM:SS format. If you want PHP to do computations on them you'll have to convert them into timestamps with strtotime(). Alternativly, you can get MySQL to do the computation for you. Functions like subtime or date_diff might be useful for you.


<?
    $aucs=mysql_query("SELECT * FROM auction"); // table name

    $now = new DateTime(); //system date
    $noww = $now->format('Y-m-d H:i:s'); // convert to this format
    $time=strtotime($noww)."<br/>"; //

    while($auc=mysql_fetch_array($aucs))
    {

        $end=$auc['endstamp']; //ending time of auction from databse

        $time1=strtotime($end)."<br/>"; //converting it into seconds
        $result=$time1-$time; //our result

        $timeleft = gmdate("H:i:s", $result); // function to convert seconds into hours,minutes and seconds

        echo $timeleft; // it prints that i.e 06:25:35 but without countdown
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消