2011-06-23 144 views
-2
select a.pdt_id, a.end_date - now() as seconds, 
    b.bid_price, c.uname, c.profile_img 
from tbl_products a 
    left join tbl_auction b on a.pdt_id=b.product_id 
    left join tbl_members c on b.member_id=c.member_id 
where a.pdt_id=183 

我稱此查詢中的setTimeout()的JavaScript的方法,對每1秒 它顯示爲MySQL查詢錯誤

pdt_id seconds  price uname   profile_img    
183  107959.000000 0.10 xxxxxxx  images/profile/no_image.jpg 

一切是正確的結果,什麼是我的問題是,當秒變成183它不顯示輸出秒數:

pdt_id price uname   profile_img    
183  0.10 xxxxxxx  images/profile/no_image.jpg 

該查詢()中的錯誤是什麼?如果需要的話我會給表的詳細信息...

+0

你在哪裏調用該查詢? –

回答

0

試試這個:

select ..., subdate(a.end_date, now()) as seconds, 
+0

這沒有返回 –

+0

如果a.end_date爲空,你會得到一個空的其他部分。現在嘗試'if_null(a.end_date,now()) - now()' – Bohemian

3

你不能做數學上的日期這樣

a.end_date - now() as seconds 

這是你的錯誤。

這裏的一個替代

UNIX_TIMESTAMP(e.end_date) - UNIX_TIMESTAMP() as seconds 

UNIX_TIMESTAMP表示日期爲1970年以來的秒數的整數,其是一位誠實的數目和它的工作原理。

你的方法,有時作品的原因是因爲NOW() - END_DATE有時候是好的,但數學的日期不基地10個號碼所以最終你會得到一個扭曲的結果,當你這樣對待他們。

+0

我也試過這個unix_timestamp(a.end_date) - unix_timestamp(''。date('Ymd H:i:s')。'')但仍然有問題 –

+0

請幫助我請 –

+0

unix_timestamp(a.end_date ) - unix_timestamp()您的日期業務不是必需的....默認是NOW。或者如果你想更加明確。 UNIX_TIMESTAMP(NOW()) –