用php进行mysql查询的进度条 [英] progress bar with mysql query with php

查看:124
本文介绍了用php进行mysql查询的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过mysql查询的迭代来更新进度条,但我不明白如何更新进度条,以及如何找到已获取的行数,例如:

i am trying to update a progress bar with the iteration of a mysql query, and i can't understand how i can update the progress bar, and how i can found what number of row i have fetched, for example:

$query = 'SELECT tvshows.genres, tvshows.id_show FROM tvshows where tvshows.genres is not NULL';
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
echo $num_rows;

此:echo $num_rows;是我获取的行数,然后以这种方式迭代结果:

this: echo $num_rows; is the number of rows i have fetched, and then in this way i iterate the result:

while ($db_row = mysql_fetch_assoc($result)) 
{
    //Do seomthing with the row

}

但是我怎么知道我要在哪一行更新然后更新进度栏?谁知道一个很好的教程或示例代码来制作进度条?我发现了这一点: http://w3shaman.com/article/php-progress-bar-脚本

but how i can know in what row i fetch to update then the progress bar? and anyone knows a good tutorial or sample code to do a progress bar? i have found this: http://w3shaman.com/article/php-progress-bar-script

但是该示例需要以下条件:

but that example require these:

 for($i=1; $i<=$total; $i++){
// Calculate the percentation
$percent = intval($i/$total * 100)."%";

我不知道如何通过php查询的结果来实现它,有人可以帮助我吗?

and i doesn't know how make it with the result of the php query, anyone can help me?

推荐答案

如注释中所述,如果必须使用进度条,它应该是非常慢的查询.

As mentioned in the comments, it should be an extemely slow query if you should have to use a progress bar.

如果是这样,您可以在循环中添加一个简单的计数器:

If it is, you could just add a simple counter to your loop:

$i = 0;
while ($db_row = mysql_fetch_assoc($result)) 
{
    $i++;
    $percent = intval($i/$num_rows * 100)."%";

    //Do seomthing with the row

}

然后按照文章中所述进行操作.

And then do as mentioned in the article.

这篇关于用php进行mysql查询的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆