0 レビュー
3 回答
PHPを使用したMySQLデータベースのタイムスタンプクエリ
phpを使用したMySQLデータベースのタイムスタンプクエリ
次のように、1ヘッド3時間に設定されたタイムスタンプ値をデータベースに挿入しました
//For 3 hours ahead of time
$reciever_time = date("Y-m-d H:i:s", strtotime('+3 hours'));
3時間以内になったら、「3時間の期限が来ています」とエコーする必要がありますが、以下のコードは「まだ3時間ではありません」とエコーし続けます。 3時間の期限です。ヘルプ
<?php
$link = mysqli_connect("localhost", "sectona", "secBBN", "sectonadb");
$q = "SELECT id,reciever_time FROM indextime WHERE id='10'";
$qu = mysqli_query($link, $q);
while($row=mysqli_fetch_array($qu, MYSQL_ASSOC)){
$id = $row['id'];
$timest = $row['reciever_time'];
}
//60secx10min is 600milisec
//60secx30min is 1800
// 30 min = 1800
// 1 hour = 1800 x2
//12 hour = 3600 x12
//1 day = 3600 x24
$time = strtotime($timest);
$curtime = time();
// execute data that is due in 3 hours
if(($curtime-$time) >= 10800) {
print "3 hours is due then update";
}
else{
print "its not yet 3 hours";
}
?>
わからない
0
レビュー
答え :
解決策:
これを試してください:
if(($time - $curtime) >= -10800) {
print "3 hours is due then update";
} else {
print "its not yet 3 hours";
}
10800
のみを負に変換します。
わからない
0
レビュー
答え :
解決策:
試すことができます:
$link = mysqli_connect("host","user","password","DBname");
$q = "SELECT id,reciever_time FROM indextime WHERE id='10' LIMIT 1";
$qu = $link->query($q);
$row = mysqli_fetch_object($qu);
$id = $row->id;
$timest = $row->reciever_time;
$time = strtotime($timest);
$curtime = time();
$message = ($curtime - $time) >= 10800 ? "3 hours is due then update" : "its not yet 3 hours";
print $message;
わからない
0
レビュー
答え :
解決策:
PHPでは、date_diff関数を使用して時間の差を取得します 試してみてください:
if(date_diff($time,$curtime) >= 10800){
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。