私はデータベースを持っており、そこにテキスト、Webページに表示される期間と時間を保存します。jsonが受け取った文字列要素を表示する日時に基づいて表示するにはどうすればよいですか?
次のようにPHPの結果は次のとおりです。
{"text_content":"dgsgdsgds","text_duration":"15","start_time":"2015-09-28 23:11:15"},{"text_content":"dgsgdsgds","text_duration":"15","start_time":"2015-09-28 23:11:30"},{"text_content":"gdsgdsgds","text_duration":"15","start_time":"2015-10-01 14:00:00"}
私は、データベースからデータを取得し、画面上に印刷しjqueryのスクリプトを持っている:
var results =[];
var cursor = 0;
function myFunction() {
$.getJSON('list2.php', function(json) {
results = json;
cursor = 0;
// Now start printing
printNext();
});
}
function printNext(){
if(cursor == results.length){
// Reset the cursor back to the beginning.
cursor = 0;
}
// Print the key1 in the div.
//$('#mydiv').html(results[cursor].key1);
$('#mydiv').hide('fast', function(){ $('#mydiv').html(results[cursor].text_content); $('#mydiv').show('fast'); });
// Set a delay for the current item to stay
// Delay is key2 * 1000 seconds
setTimeout(function(){
printNext();
}, results[cursor].text_duration * 1000);
// Advance the cursor.
cursor++;
}
を、今、私が欲しかったですstart_time
のように、データベースからフェッチされた日付にのみテキストが画面に表示される機能を追加することはできますが、サーバーコードへのアクセスを一切持たずにjqueryのみで実行できるかどうかわかりません。 次のようなif文を追加しようとしました:
if(results[cursor].start_time == new Date()){
これは画面に印刷する直前ですが、トリックはしませんでした。あなたはそれを手伝ってもらえますか? ありがとう!
より良いDBからの時間に基づいて、必要なデータのみを取り出します。 @ randomuser1 –
私はそれについて考えましたが、1時間ごとにデータを取得し、その時間の分に応じてデータを表示する繰り返しクエリを実行したいと考えています。 – randomuser1