显示大量mysql记录

发布于 2024-10-04 03:04:38 字数 131 浏览 2 评论 0原文

如果我有一个包含 7000 条记录的 mysql 数据库,我必须在我的网页上显示所有 7000 条记录。是否有任何提示和技巧可以加快该过程(浏览器在显示所有记录之前几乎崩溃)我知道我应该查询它以减少所选记录的数量,但我实际上需要显示 7000...

If i had a mysql db with 7000 records in it and i had to display all 7000 on my webpage. Are there any tips and tricks to speed the process up (the browser practically crashes before showing all the records) i know i should query it to reduce the number of records selected but i actually need to display 7000...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一城柳絮吹成雪 2024-10-11 03:04:38

打开输出缓冲:http://php.net/manual/en/function。 ob-start.php

<?php

ob_start(); 

// do work...

ob_end_flush();

?>

编辑

以下 php 获取 10K 产品并将其输出为表格,在 0.014 秒内没有任何问题。

<?php

ob_start(); 

$conn = new Mysqli("localhost", "vldb_dbo", "pass", "vldb_db");

$startTime = microtime(true);

$result = $conn->query(sprintf("call list_products(%d)", 10000));

echo "<table border='1'>";

while($row = $result->fetch_assoc()){
 echo sprintf("<tr><td>%s</td><td>%s</td></tr>", $row["prod_id"], $row["name"]);
}

echo "</table>";

echo sprintf("<br/>Page generated in %s secs",number_format(microtime(true) - $startTime, 6, ".", ""));

$result->close();   
$conn->close();

ob_end_flush();

?>

SQL 脚本

drop procedure if exists list_products;
delimiter #

create procedure list_products
(
in p_prod_id int unsigned
)
begin
    select * from product where prod_id between 1 and p_prod_id;
end #

delimiter ;

也可以很好地处理 50K 记录,除了运行时潜水 - 页面在 0.112902 秒内生成

EDIT2

http://phplens.com/lens/php-book/optimizing-debugging-php.php

上述链接的摘录:

加快上述速度的另一种方法
代码将使用输出缓冲。
这将累积输出字符串
内部,并将输出集中发送
在剧本的最后拍摄。这
减少网络开销
实质上是以更多的代价
内存和延迟的增加。在
我的一些代码完全由
echo 语句、性能
改进了 15%
观察到。

Turn on output buffering : http://php.net/manual/en/function.ob-start.php

<?php

ob_start(); 

// do work...

ob_end_flush();

?>

EDIT

The following php fetches 10K products and outputs them as a table with no problems in 0.014 seconds.

<?php

ob_start(); 

$conn = new Mysqli("localhost", "vldb_dbo", "pass", "vldb_db");

$startTime = microtime(true);

$result = $conn->query(sprintf("call list_products(%d)", 10000));

echo "<table border='1'>";

while($row = $result->fetch_assoc()){
 echo sprintf("<tr><td>%s</td><td>%s</td></tr>", $row["prod_id"], $row["name"]);
}

echo "</table>";

echo sprintf("<br/>Page generated in %s secs",number_format(microtime(true) - $startTime, 6, ".", ""));

$result->close();   
$conn->close();

ob_end_flush();

?>

SQL Script

drop procedure if exists list_products;
delimiter #

create procedure list_products
(
in p_prod_id int unsigned
)
begin
    select * from product where prod_id between 1 and p_prod_id;
end #

delimiter ;

Works fine with 50K records too except runtime dives - Page generated in 0.112902 secs

EDIT2

http://phplens.com/lens/php-book/optimizing-debugging-php.php

An excerpt from the above link:

An alternate way of speeding the above
code would be to use output buffering.
This will accumulate the output string
internally, and send the output in one
shot at the end of the script. This
reduces networking overhead
substantially at the cost of more
memory and an increase in latency. In
some of my code consisting entirely of
echo statements, performance
improvements of 15% have been
observed.

写给空气的情书 2024-10-11 03:04:38

我假设您在 PHP 中执行此操作(我不熟悉),但这对所有语言都是通用的。

首先将7000条记录查询到一个列表中,然后在脚本页面(例如php、jsp for java等)中显示所有列表。不允许您的 php 页面打开连接,读取列表中的每个项目并显示它们。客户端(浏览器)可能会无限期等待并导致会话超时

I'm assuming you're doing this in PHP (which I'm not familiar with) but this is generic to all languages.

Query 7000 records into a list first, then display all the list in a scripting page (e.g. php, jsp for java, etc.). Don't allow your php page to open the connection, read each item from the list and displaying them. The client (browser) might wait indefinitely and cause a session timeout

顾挽 2024-10-11 03:04:38

f00:如果他将结果显示在表格中,浏览器将继续显示数据,但无论如何都不会正确显示。据我所知,该表无法正确渲染(在 Firefox 中)...
我认为对表进行分页是唯一可能的解决方案......

f00: if he displays the result in table and the browser will survive to display the data, they wont be displayed correcly anyways. As far as I know, the table wont render correctly (in firefox)...
I think that paging the table is the only possible solution...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文