Html自动刷新表格
我写了这个简单的代码和这个我已连接到 mysql 数据库的表。它获取我插入数据库中的数据,我想要的是页面自动刷新,而不必刷新整个页面。
我的代码:
<html>
<head>
<title>Whats Up?</title>
</head>
<body>
<a href="Register.php">Register</a> <a href="login.php">Login</a>
<?php
mysql_connect('localhost', 'root');
mysql_select_db('summerinstitute');
$query="SELECT * FROM students";
$result=mysql_query($query);
echo "<table border=\"1\">";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>";
echo $row['fname'];
echo "</td>";
echo "<td>";
echo $row['lname'];
echo "</td>";
echo "<td>";
echo $row['username'];
echo "</td>";
echo "<td>";
echo $row['Email'];
echo "</td>";
echo "</tr>";}
?>
</body>
</html>
I wrote this simple code and this table which I have connected to mysql database. It fetches the data I inserted in my database what I want is for the page to automatically refresh on its own without having to refresh the whole page.
My Code:
<html>
<head>
<title>Whats Up?</title>
</head>
<body>
<a href="Register.php">Register</a> <a href="login.php">Login</a>
<?php
mysql_connect('localhost', 'root');
mysql_select_db('summerinstitute');
$query="SELECT * FROM students";
$result=mysql_query($query);
echo "<table border=\"1\">";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>";
echo $row['fname'];
echo "</td>";
echo "<td>";
echo $row['lname'];
echo "</td>";
echo "<td>";
echo $row['username'];
echo "</td>";
echo "<td>";
echo $row['Email'];
echo "</td>";
echo "</tr>";}
?>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要使用 javascript 和一些 ajax 实现来仅
刷新
页面的一部分。例如使用 jQuery:
php page1.php:
php page2.php:
page1.php 上的 Javascript(将其放在标题中):
You need to use javascript and some ajax implementation to only
refresh
a part of the page.For example with jQuery:
php page1.php:
php page2.php:
Javascript on page1.php (put it in the header):
查看
http://en.wikipedia.org/wiki/Ajax_%28programming%29
它会回答你的问题
Look on
http://en.wikipedia.org/wiki/Ajax_%28programming%29
it will answer your questions
阿贾克斯
Ajax
使用 jQuery
Using jQuery
我没有对 PHP 做太多工作,但您可能希望 PHP 在它自己的单独页面上创建表,然后在您想要刷新表时使用 AJAX 来获取数据。如果你使用 dojo 你可以做这样的事情。
index.html
my_table.php
I haven't done much with PHP, but you probably want that PHP that creates the table on it's own separate page, and then use AJAX to get the data whenever you want to refresh the table. If you use dojo you could do something like this.
index.html
my_table.php