[英]How to dynamically show how many mysql queries have been executed on a page?
I have a PHP page that could potentially result in a lot of mySQL queries depending on what the user searches. 我有一个PHP页面,根据用户搜索的内容,可能会导致很多mySQL查询。 For searches that will take a long time, I want to show the user that something is happening, so they don't think the page is broken or hanging.
对于需要很长时间的搜索,我想向用户显示正在发生的事情,因此他们不认为页面已损坏或挂起。 I can't make a progress bar because I do not know how many queries will be executed every time.
我无法创建进度条,因为我不知道每次都会执行多少个查询。 It depends on the search.
这取决于搜索。 I was thinking of having a number on the side of the page that would correspond to the number of queries and this number would increase continuously until the search is over.
我当时在想页面的侧面上有一个与查询数量相对应的数字,并且这个数字会不断增加,直到搜索结束。
This is how I am executing my queries. 这就是我执行查询的方式。
$query = "SELECT name, id, direct_owner FROM $table WHERE parent_id = '$ownerID'";
$result = mysqli_query($connection, $query);
I am submitting a form for each search and then I use 我为每次搜索提交一个表格,然后使用
if(isset($_POST['submit'])
PHP is server-side, it will not be able to show anything in realtime, you'd need client-side like Javascript
or Angular
or Jquery
for any frameworks. PHP是服务器端的,它将无法实时显示任何内容,对于任何框架,您都需要像
Javascript
或Angular
或Jquery
这样的客户端。
I "lied" a bit, you can do real-time, but it's very hackish. 我“撒谎”了一点,您可以实时进行操作,但是它非常骇人。 You can read about
flush()
here . 您可以在此处阅读有关
flush()
信息 。 I wouldn't recommend it, and regardless, you can't do a progress bar with just PHP. 我不会推荐它,而且无论如何,您不能仅使用PHP来创建进度条。
What you should do is create this PHP file as a postRequest
type and query it using AJAX
, which is capable of doing live-output and a progress bar. 您应该做的是将此PHP文件创建为
postRequest
类型,并使用AJAX
查询,该AJAX
能够进行实时输出和进度条。 There are multiple libraries out there to help you. 有多个库可以为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.