私は数ヶ月のデータベースt_calibratorでint
データを(calperiod = 12、24および36)があると私は$callast
に私の入力日付を計算したい、PHP:データベースから月の日付を追加する方法は?
この私の作成したコード(常に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の後にドットが欠けています。 $ =日付追加( 'Y-M-D' のstrtotime( '+' の$ calperiodを '月' のstrtotime($のcallast))。)。私はあなたのコードを使用している場合、私はこの –
@MayaShahを得た:回復可能致命的なエラー:クラスmysqli_resultのオブジェクトは、データベースからの$ calperiodのために取得しているその値は文字列 –
に変換することができませんでしたか? –