PHP:在指定的时间内回显消息 [英] PHP : echo message for a specified amount of time
问题描述
我想显示一个字符串您的状态已发布,持续约3秒钟,而不是我希望它消失的时间。
I want to display a string "Your status has been posted" for something around 3 or so seconds than I want it to go away.
截至目前我有一个新闻提要,用户可以在其中发布消息,并在它们发布后回显该文本字符串,直到重新输入URL。有人有什么建议吗?
As of right now I have a news feed where the user can post messages and after they post it echoes that string of text until the url is re-enetered. Does anyone have any suggestions?
if ($_POST['submit'])
{
$body = $_POST['body'];
if ($body)
{
include ('connect.php');
$date = date("Y-m-d");
$email = $_SESSION['email'];
$who = mysql_query("SELECT firstname FROM people WHERE email = $email");
$insert = mysql_query("
INSERT INTO status VALUES('','$email','$body','$date')");
echo ('Your status has been posted <p></p>');
}
else
echo 'Status required to post into news feed! <p></p>';
}
?>
状态:
感谢您的帮助!
Jeff
推荐答案
您需要添加一些JavaScript才能执行此操作。以下是入门的概述:
You need to add some JavaScript to do this. Here is an outline to get you started:
<p id="info-message">Your status has been posted</p>
<script>
setTimeout(function(){
document.getElementById('info-message').style.display = 'none';
/* or
var item = document.getElementById('info-message')
item.parentNode.removeChild(item);
*/
}, 3000);
</script>
另外,您可能希望淡出效果。为此,我建议使用jQuery或Scriptaculous之类的库。
Also you may want fade-out effects. For that I'd recommend using a library like jQuery or Scriptaculous.
有用的链接:
https://developer.mozilla.org/zh-CN/Window.setTimeout
http://api.jquery.com/fadeOut/
http://script.aculo.us/
哦,顺便说一下,您的脚本容易受到 SQL注入的影响。 >始终转义您的查询参数(或使用准备好的查询)!
Oh, by the way, your script is vulnerable to SQL injection. Always escape your query parameters (or use prepared queries)!
这篇关于PHP:在指定的时间内回显消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!