Reputation: 9273
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;
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
}
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)."%";
and i doesn't know how make it with the result of the php query, anyone can help me?
Upvotes: 1
Views: 19669
Reputation: 1477
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.
Upvotes: 4