使用php和mysql显示百分比的可能性

时间:2023-01-05 22:17:21

Hai in my mysql database i have around 20,000 records. User will give input to get certain results on the screen. Now when user provides his input and clicks on submit, a GIF image which keeps circling till the result is displayed on screen.

在我的mysql数据库中我有大约20,000条记录。用户将提供输入以在屏幕上获得某些结果。现在,当用户提供他的输入并点击提交时,GIF图像会一直盘旋直到结果显示在屏幕上。

But i would like to display percentage (Loading 10%) instead of GIF image. Usually users provide date rage to fetch data so query will select data between given date range. So please give me an idea how i can how the percentage to users

但我想显示百分比(加载10%)而不是GIF图像。通常用户提供日期范围以获取数据,因此查询将在给定日期范围之间选择数据。那么请告诉我如何才能将百分比如何用于用户

Thank You..

1 个解决方案

#1


0  

You have a few options, I am assuming you are using just one AJAX request to the server that returns the data.

您有几个选项,我假设您只使用一个AJAX请求返回数据的服务器。

1: If you are only doing one ajax request, then the only state you can watch is the AJAX requests state and change the percentage based on that. The problem with this is there is a big percentage change in time of the request between sending the request and receiving the result from the server.

1:如果您只执行一个ajax请求,那么您可以观察的唯一状态是AJAX请求状态并根据该状态更改百分比。这样做的问题是,在发送请求和从服务器接收结果之间,请求的时间变化很大。

2: You could send multiple requests and somehow track where the data ended of the first request and go through only sending small amounts of data at a time. This has the problem that it is taxing on how many requests you have to make and you are better off just returning all the data once.

2:您可以发送多个请求,并以某种方式跟踪第一个请求的数据结束位置,并且一次只发送少量数据。这就产生了一个问题,就是你需要做多少次请求,而你最好只返回一次所有数据。

The server shouldn't take much time at all getting all the data together so long as your table is optimised. I am guessing your main problem is the response being large (>1MB). Unless the data is only 20,000 rows, just try and cut down unnecessary data you are sending down and it should be quite a quick request.

只要您的表经过优化,服务器就不应该花费太多时间将所有数据放在一起。我猜你的主要问题是响应很大(> 1MB)。除非数据只有20,000行,否则只需尝试减少发送的不必要数据,这应该是一个非常快速的请求。

By the looks of this questions there is one way to check how many bytes have been download but it is not compatible with certain browsers.

通过这些问题的外观,有一种方法可以检查已下载的字节数,但它与某些浏览器不兼容。

You are probably best off just limiting the data you return and offering paging options to the user if their request returned more than X results.

如果他们的请求返回的结果超过X,那么您最好只限制返回的数据并为用户提供分页选项。

#1


0  

You have a few options, I am assuming you are using just one AJAX request to the server that returns the data.

您有几个选项,我假设您只使用一个AJAX请求返回数据的服务器。

1: If you are only doing one ajax request, then the only state you can watch is the AJAX requests state and change the percentage based on that. The problem with this is there is a big percentage change in time of the request between sending the request and receiving the result from the server.

1:如果您只执行一个ajax请求,那么您可以观察的唯一状态是AJAX请求状态并根据该状态更改百分比。这样做的问题是,在发送请求和从服务器接收结果之间,请求的时间变化很大。

2: You could send multiple requests and somehow track where the data ended of the first request and go through only sending small amounts of data at a time. This has the problem that it is taxing on how many requests you have to make and you are better off just returning all the data once.

2:您可以发送多个请求,并以某种方式跟踪第一个请求的数据结束位置,并且一次只发送少量数据。这就产生了一个问题,就是你需要做多少次请求,而你最好只返回一次所有数据。

The server shouldn't take much time at all getting all the data together so long as your table is optimised. I am guessing your main problem is the response being large (>1MB). Unless the data is only 20,000 rows, just try and cut down unnecessary data you are sending down and it should be quite a quick request.

只要您的表经过优化,服务器就不应该花费太多时间将所有数据放在一起。我猜你的主要问题是响应很大(> 1MB)。除非数据只有20,000行,否则只需尝试减少发送的不必要数据,这应该是一个非常快速的请求。

By the looks of this questions there is one way to check how many bytes have been download but it is not compatible with certain browsers.

通过这些问题的外观,有一种方法可以检查已下载的字节数,但它与某些浏览器不兼容。

You are probably best off just limiting the data you return and offering paging options to the user if their request returned more than X results.

如果他们的请求返回的结果超过X,那么您最好只限制返回的数据并为用户提供分页选项。