私はどのようにデータベースに格納されたデータのIDをエコーするPHPスクリプトを作ることができますか質問したいと思います。例えば、2分後に特定の時間の後にそれ自身を繰り返します.iはcron仕事や別のスケジューラー。ちょうどPHPやjavascriptの実装。事前にお越しいただけます。autorepeat PHPスクリプト
答えて
私はこのスクリプトと同様に行っています。ユーザーはページ上にある間に、2分ごとにscriptToRun.php
を実行します。 @JMCクリエイティブへ
function changeFeedAddress() {
$.ajax({
type: 'get',
url: 'scriptToRun.php',
success: function(txt) {
// do something with the new RSS feed ID here
}
});
}
setInterval(changeFeedAddress,120000); // 2 MINUTES
これは彼がJQueryを使用していると仮定しています。 – dqhendricks
jqueryは問題ありません。あなたが言及しているscriptToRun.phpも、スクリプト自体または別のスクリプトの名前ですか? – olaf36
いいえ、 'scriptToRun.php'はサーバー上に存在する別のスクリプトです。唯一の目的は、新しいフィードIDを取得してそれをエコーバックすることです。 – JakeParis
代替(例のために自己完結型):
<?php
// check if the $.post below is calling this script
if (isset($_POST['ajax']))
{
// $data = /*Retrieve the id in the database*/;
// ---vvvv---remove---vvvv---
// Example Data for test purposes
$data = rand(1,9999);
// End Example Data
// ---^^^^---remove---^^^^---
// output the new ID to the page so the $.post can see it
echo $data;
exit; // and stop processing
}
?>
<html>
<head>
<title>Demo Update</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// assign a timeout for this script
var timeout = 2 * 60000; // 2 minutes
// create a function we can call over and over to fetch the ID
function updateDBValue(){
// call this same script and retrieve an "id from the database" (see top of page)
$.post('<?php echo $_SERVER['PHP_SELF']; ?>',{ajax:true},function(data){
// 'data' now contains the new ID. For example's sake, place the value
// in to an input field (as shown below)
$('#db-value').val(data);
// set a timer to re-call this function again
setTimeout(updateDBValue,timeout);
});
}
// call the function initially
updateDBValue();
});
</script>
</head>
<body style="text-align:center;">
<div style="margin: 0 auto;border:1px solid #000;display:block;width:150px;height:50px;">
DB Value:<br />
<input type="text" id="db-value" style="text-align:center;" />
</div>
</body>
</head>
理由だけでこれをしませんか?
<?php
header('refresh: 600; url=http://www.yourhost.com/yourscript.php');
//script here
?>
あなたのIDをスクリプト内から無作為に生成していれば、これはうまくいきます。ページは10分ごとに更新されます。
ページがリフレッシュされるときに '$ _SESSION ['id'] = LASTID'を使用する必要がある場合は、最後に使用したID –
- 1. PHPスクリプト
- 2. PHPスクリプト
- 3. PHPスクリプト
- 4. PHPスクリプト
- 5. HTMLスクリプトは、PHPスクリプトに
- 6. は、PHPスクリプト
- 7. PHP認証スクリプト
- 8. PHPスクリプトのエラー
- 9. メールPHPスクリプト
- 10. PHPのPythonスクリプト
- 11. エンコーディングPHPスクリプト
- 12. PHP:画像スクリプト
- 13. ダイナミックリダイレクトのPHPスクリプト
- 14. コールPHPスクリプト
- 15. PHPスクリプトのスピードダンプ
- 16. PHPスクリプトのヘルプ
- 17. PHPのMD5スクリプト
- 18. memory_limit issue PHPスクリプト
- 19. スケジューリングPHPスクリプト
- 20. PHP検索スクリプト
- 21. wp_enqueue_scriptとPHPスクリプト
- 22. エラー:PHPスクリプトの
- 23. PHPスクリプト(スキャナー)
- 24. ロードPHPスクリプト
- 25. PHPエコーブレークタグ私のPHPスクリプトで
- 26. PHPスクリプト内のPHPエコー
- 27. PHPスクリプトのMySQL_Queryエラー
- 28. 自動化PHPスクリプト
- 29. bashのループPHPスクリプト
- 30. PHPファイル削除スクリプト
なぜあなたはcronジョブを使いたくないですか? – DTest
自動リロードするページが必要な場合:[meta refresh](http://en.wikipedia.org/wiki/Meta_refresh)。それがあなたが必要とするものでない場合は、あなたの質問を明確にしてください。 – drudge
正直なところ私はそれを使用する方法を知らない。しかし、これは理由ではない!私はPHPやjavascriptでそれを実装することを好む... – olaf36