General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 25th, 2004, 04:32 AM
ChrisIves ChrisIves is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 8 ChrisIves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
HowTo: Progressive Loading.

Hi all. I recently added this neat little feature to a page I did that queries 3rd party servers and reports back with information. Since it queries other peoples servers, there could be a lot of wait time. It was very ugly having the entire page flash up 15 seconds later.

So I needed a way to have the page load progressively, but my page layout didn't let me just flush() periodically, as closing table tags where not there. It needed to work on IE and Mozilla atleast.

Solution? Javascript and flush() in PHP. I have had some requests for people wanting to do this, so here it is.

PHP Code:
<?
     $data 
= array("data 1""data 2""data 3""data 4");
     
     echo 
"<table width=50% align=center border=1>";
     
     for(
$i=0$i<count($data); $i++){
          echo 
"<tr><td id=\"data_$i\" style=\"background: #FFFFAA\">Connecting..</span></td></tr>";
     }
     
     echo 
"</table>";
     
     
flush();
          
     for(
$i=0$i<count($data); $i++){
          if(
$i == 2){
               echo 
"
               <script>
                    document.getElementById('data_$i').innerHTML = '<font color=#FF0000>Server Down</font>';
                    document.getElementById('data_$i').style.backgroun  d = '#FFAAAA';
               </script>
               "
;
          }else{
               echo 
"
               <script>
                    document.getElementById('data_$i').innerHTML = '$data[$i]';
                    document.getElementById('data_$i').style.backgroun  d = '#AAFFAA';
               </script>"
;
          }
          
          
flush();
          
sleep(1);     // simulate lag
     
}
?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > HowTo: Progressive Loading.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT