MySQL和PHP加载超过1000个项目使浏览器冻结 [英] MySQL & PHP load more then 1000 items makes browser freeze
问题描述
从数据库加载数据时,我遇到了一个小问题.我有1150行的表格,我希望将它们显示在一页上.
I have a small issue with loading my data from database. I have table with 1150 rows, and I would love to show them on single page.
这是我的SELECT
:
$result = mysqli_query($link, "SELECT id as id, name as name FROM table") or die;
这是我的PHP:
while ($zaznam = mysqli_fetch_array($result)):
extract($zaznam);
echo $id ."-". $name;
endwhile;
效果很好,但是页面加载大约10秒钟,并且在SELECT期间浏览器被冻结.
It works good, but page is loading about 10 sec and browser is frozen during the SELECT.
是否有机会加快速度,或者仅显示部分项目,然后滚动加载等等?
Is there any chance to speed this up, or show only part of items and on scroll load next and so on?
推荐答案
您碰到了头上的钉子.建议将其打印在页面中.将LIMIT
添加到您的SQL查询.另外,不要在循环中echo
.相反,请附加到变量,然后在末尾回显.
You hit the nail on the head. Printing this in pages is advisable. Add a LIMIT
to your SQL query. Also, don't echo
in your loop. Instead, append to a variable then echo at the end.
这篇关于MySQL和PHP加载超过1000个项目使浏览器冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!