大佬教程收集整理的这篇文章主要介绍了PHP – 显示更多文章功能反馈,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
但是,我正在制作的系统将会使用很长时间(小公司的学生项目)并且会有很多文章.我不希望用户和服务器必须在网页上一次加载所有文章.我有想法如何做到这一点,但我想先由其他人运行这个想法.
从概念上讲,我正在考虑做的是在页面上加载一些文章.在底部,会有一个“显示更多”按钮或链接,可以从数据库中读取和显示更多文章(希望无需重新加载页面,但我非常怀疑它是否可行).
实际上,它可能会是这样的:使用表单,在隐藏字段中存储显示文章的数量,在提交“显示更多”重新加载页面并使用$_POST和while循环显示存储的数字更多文章.这是下面的简化示例.
<form method="post" action="articlePage.php"> <?php if(isset($_POST["articleCount"])){ $articleCount = $_POST["articleCount"] + 5; } else{ $articleCount = 5 } //Assuming we open the connect,execute the query and then close the connection $count = 0; while($result = mysqli_fetch_array($SELEctNews) && $count <= $articleCount){ echo $result["articlename"] . "<br/>"; count = count + 1; } echo "<input type='hidden' value='" . $articleCount . '" name='articleCount'/>"; ?> <input type="submit" value="Show more"/> </form>
我的问题是:
>有更有效/更好的方法来解决这个问题吗?
>有没有办法我不必重新加载页面?
任何提示或信息都非常感谢!我在提问时有点新意,所以如果有任何遗漏,请告诉我
function getArticleCount(){ if(isset($_POST["articleCount"])){ $articleCount = $_POST["articleCount"] + 5; } else{ $articleCount = 5 } //Assuming we open the connect,execute the query and then close the connection $count = 0; while($result = mysqli_fetch_array($SELEctNews) && $count <= $articleCount){ echo $result["articlename"] . "<br/>"; count = count + 1; } echo "<input type='hidden' value='" . $articleCount . '" name='articleCount'/>"; } getArticleCount();
这是一个使用AJAX and PHP一起给你一个感觉的例子.
以上是大佬教程为你收集整理的PHP – 显示更多文章功能反馈全部内容,希望文章能够帮你解决PHP – 显示更多文章功能反馈所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。