我有int
數據(calperiod = 12,24和36)個月,我想在我的$callast
輸入的日期來計算,PHP:如何從數據庫中添加月份數量?在數據庫t_calibrator
這是我創建的代碼(但總是1970-01-01) :
$calperiod = mysqli_query($conn, "SELECT calperiod FROM t_calibrator WHERE id_calibrator='$id_calibrator'");
$add = date('Y-m-d', strtotime('+".$calperiod" month', strtotime($callast)));
我的參考碼從$add = date('Y-m-d', strtotime('+24 month', strtotime($callast)));
得到,是的,但是隻有24個月。
UPDATE 現在我嘗試使用此代碼:
$sql = "SELECT * FROM t_calibrator WHERE id_calibrator = '$id_calibrator'";
$result = mysqli_query ($conn,$sql);
$caldata = mysqli_fetch_array ($result);
$add = date('Y-m-d', strtotime('+".$caldata['calperiod']." months', strtotime($callast)));
但是這樣的示值誤差:
Parse error: syntax error, unexpected 'calperiod' (T_STRING), expecting ',' or ')' in /storage/h7/747/1148747/public_html/pages/calinputhistory.php on line 19
任何一個可以幫我這個麻煩? (對不起我的英文不好)
您錯過了$ calperiod後的點。 $ add = date('Y-m-d',strtotime('+'。$ calperiod。'month',strtotime($ callast))); –
@MayaShah如果我使用你的代碼,我得到這個:可恢復的致命錯誤:類mysqli_result的對象不能轉換爲字符串 –
你從$數據庫中獲得$ calperiod的值? –