brianmfalls
asked on
PHP For Loop - Updating a span for each record processed in loop
Prior to my loop, I have the following header encapsulating a span which outputs the variable $count (set to 0 to begin with):
Within my loop I am incrementing the value of $count by one:
That's all fine and good, but I don't know how to update the span without using JavaScript for each iteration of the loop. I can make it happen all day in ColdFusion and/or JavaScript. There has to be an equivalent PHP solution. I'm all ears! How do I update the span with the incremented value of $count using only PHP?
$count = 0;
echo '<h4>Compiled Data (<span class="changeNumber">', $count, '</span> Records):</h4>';
Within my loop I am incrementing the value of $count by one:
$count++
That's all fine and good, but I don't know how to update the span without using JavaScript for each iteration of the loop. I can make it happen all day in ColdFusion and/or JavaScript. There has to be an equivalent PHP solution. I'm all ears! How do I update the span with the incremented value of $count using only PHP?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See if this helps...
https://www.experts-exchange.com/articles/14519/A-jQuery-Progress-Bar.html
https://www.experts-exchange.com/articles/14519/A-jQuery-Progress-Bar.html
ASKER
I figured it out. For reasons I'm still looking into, jQuery wasn't loaded in the iFrame where all the fun is taking place. I rewrote the script with the standard, non-jQuery equivalent, then changed the class attribute to an id attribute on the counter, and viola! It works.
echo '<h4>Compiled Data (<span id="changeNumber">', $count, '</span> Records):</h4>';
echo "<script>document.getElementById('changeNumber').innerHTML='$count';</script>";
This iteration simply updates the counter as the data is processed. It moves in chunks rather than one at a time, but it works none the less. I'll post up the reverse iteration when I get it done. Shouldn't be long. Then I'll split the points between y'all and call it done. Thanks for the input guys!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ray,
jQuery's progress bar is a great solution, but it wouldn't play nice with what I have. It would be difficult, if not impossible to shut it down when the processing is complete. iFrames suck in that respect. I hate using them, but was left with no option in this instance. Even though I am calling the iFrame through our existing framework, jQuery isn't loading... I'm not sure I want to open that bag of worms at the moment, since everything is working, and I have a great deal of work yet to do and not a lot of time to get it done. I know one thing though, it is being called in through the framework, since I can see the the style sheets are being leveraged. It seems that only jQuery is awol.
I am currently using a Bootstrap modal loading variant that I was easily able to close post to processing completion. It looks great, and in addition to the modal and the loading animation, the user can now see the records count down to 0. It's exactly what I was shooting for.
Thank you VERY much for your valuable input.
Brian
jQuery's progress bar is a great solution, but it wouldn't play nice with what I have. It would be difficult, if not impossible to shut it down when the processing is complete. iFrames suck in that respect. I hate using them, but was left with no option in this instance. Even though I am calling the iFrame through our existing framework, jQuery isn't loading... I'm not sure I want to open that bag of worms at the moment, since everything is working, and I have a great deal of work yet to do and not a lot of time to get it done. I know one thing though, it is being called in through the framework, since I can see the the style sheets are being leveraged. It seems that only jQuery is awol.
I am currently using a Bootstrap modal loading variant that I was easily able to close post to processing completion. It looks great, and in addition to the modal and the loading animation, the user can now see the records count down to 0. It's exactly what I was shooting for.
Thank you VERY much for your valuable input.
Brian
ASKER
I accepted my own solution because it was the actual solution. The others' input was relevant and helpful in leading me to my solution, which is why I credited them as well.
ASKER
The purpose of updating the count is to entertain the end user. If they see that the page is working, they are less likely to do something stupid, like refreshing the screen while the data is still being processed. My end goal is to display the total, and to display a reverse counter that will count down from the total records being processed to 0. The average records being processed are between 1700 and 1800. As you would expect, that takes quite some time. While there is a loading modal in place during processing, the user may be inclined to think that the process is stuck. The counter would assure them that the process is running, and not stuck.
So... Via my current, and somewhat educated but ignorant, understanding of PHP, I expected that this script (jQuery) would happily update our counter:
Open in new window
Clearly, it doesn't. How can I make it work?
Ray, I'm off to read your article right now. :)