使用jquery刷新动态php div

使用jquery刷新动态php div,php,jquery,mysql,loading,Php,Jquery,Mysql,Loading,我使用php/while循环将mysql结果打印到div中。现在我需要在使用jquery插件或代码单击任何链接、按钮后刷新此结果。更好的设计点击链接后,用户看到任何加载消息(请稍候),jquery/php打印新结果(刷新div)。这可能吗?有办法做到这一点吗 我的部门是: <a class="click" href="#"> Link TO refresh Div </a> <div class="messagelist"> <?PHP $result=

我使用php/while循环将mysql结果打印到div中。现在我需要在使用jquery插件或代码单击任何链接、按钮后刷新此结果。更好的设计点击链接后,用户看到任何加载消息(请稍候),jquery/php打印新结果(刷新div)。这可能吗?有办法做到这一点吗

我的部门是:

<a class="click" href="#"> Link TO refresh Div </a>
<div class="messagelist">
<?PHP $result=mysql_query("select * from messages where id<'$lastmsg' order by id desc limit 20");
$count=mysql_num_rows($result);
<div class="commentbox">
while($row=mysql_fetch_assoc($result))
{?>
<li>
<?php echo $row['id'] . ' #' . $row['date'] . ' / ' . $row['comment']; ?>
</li>
<?PHP } ?>
</div>
</div>


要想做你想做的事情,你需要使用Ajax

1.创建一个单独的PHP文件,其中包含mysql结果,即下面创建的html片段

messages.php的内容

<?PHP $result=mysql_query("select * from messages where id<'$lastmsg' order by id desc limit 20");
$count=mysql_num_rows($result);
<div class="commentbox">
<ul>
while($row=mysql_fetch_assoc($result))
{?>
<li>
<?php echo $row['id'] . ' #' . $row['date'] . ' / ' . $row['comment']; ?>
</li>
</ul>
</div>
<?PHP } ?>

我还没有测试上面的代码,但它应该可以工作。

要做您想做的事情,您需要使用Ajax

1.创建一个单独的PHP文件,其中包含mysql结果,即下面创建的html片段

messages.php的内容

<?PHP $result=mysql_query("select * from messages where id<'$lastmsg' order by id desc limit 20");
$count=mysql_num_rows($result);
<div class="commentbox">
<ul>
while($row=mysql_fetch_assoc($result))
{?>
<li>
<?php echo $row['id'] . ' #' . $row['date'] . ' / ' . $row['comment']; ?>
</li>
</ul>
</div>
<?PHP } ?>

我还没有测试上面的代码,但它应该可以工作。

您的脚本无法工作。您正在混合使用PHP和HTML:

$count=mysql_num_rows($result);
<div class="commentbox"> /*THIS IS WRONG*/
while($row=mysql_fetch_assoc($result))
list.php的内容

<?PHP $result=mysql_query("select * from messages where id<'$lastmsg' order by id desc limit 20");
$count=mysql_num_rows($result);
while($row=mysql_fetch_assoc($result))
{?>
<li>
<?php echo $row['id'] . ' #' . $row['date'] . ' / ' . $row['comment']; ?>
</li>
<?PHP } ?>

您的脚本无法工作。您正在混合使用PHP和HTML:

$count=mysql_num_rows($result);
<div class="commentbox"> /*THIS IS WRONG*/
while($row=mysql_fetch_assoc($result))
list.php的内容

<?PHP $result=mysql_query("select * from messages where id<'$lastmsg' order by id desc limit 20");
$count=mysql_num_rows($result);
while($row=mysql_fetch_assoc($result))
{?>
<li>
<?php echo $row['id'] . ' #' . $row['date'] . ' / ' . $row['comment']; ?>
</li>
<?PHP } ?>

在元素中添加一个
onclick

<a onclick="loadPhp();">Reload php function</a>

在元素中添加一个
onclick

<a onclick="loadPhp();">Reload php function</a>

事实上,事实上我不知道。我是jquery的业余爱好者。谢谢你的努力!事实上,事实上我不知道。我是jquery的业余爱好者。谢谢你的努力!使用jquery外部加载/文档已准备就绪,在我的页面中加载时,我的jquery库和其他代码无法与外部页面一起工作。我不完全理解您的意思。ajax不是您的选择吗?你所做的只是在主文件中添加一些javascript并创建一个单独的php文件。看看我的眼睛。@Alex:你是说失踪者?
    也丢失了。使用jquery外部加载/文档已准备就绪。在我的页面中加载时,我的jquery库和其他代码无法与外部页面一起工作。我不完全理解您的意思。ajax不是您的选择吗?你所做的只是在主文件中添加一些javascript并创建一个单独的php文件。看看我的眼睛。@Alex:你是说失踪者?
      也丢失了。我不需要使用这种方法:加载外部页面。使用相同的页面。但是谢谢你的回答。没有第二个文件是不可能的。我不需要这个方法:加载外部页面。使用相同的页面。但是谢谢你的回答。没有第二个文件是不可能的。