real-time output from MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

real-time output from MySQL

Post by malcolmboston »

ok, i believe this is possible because i read a post on these forums a while back about it but having searched for it for the last 40 minutes i can't find it.

I have an idea for a site im creating, im expecting a rather large number of members and would like to lower the pain of loading times by outputting the information to the browser as it happens.

so for example:

i query the database and decide to print the created array
instantly it prints number 1
then number 2 as it finds it
then number 3 as it finds it
etc

i believe this can be achieved, and i remember reading something about ob_start() in the topic

If anyone can locate the topic or tell me more it would be great

Mal
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

have a look at this section of the manual

http://se.php.net/manual/en/function.flush.php

I had a bash at it in the early stages of my PHP learning, but haven't used it recently.

I strongly advise reading all the user comments, because you may have to use certain technique for it to work in certain browsers.

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Thank you bech

That looks promising........
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What i like to do when retrieving large amounts of data for output is to do something like my example here

http://www.infinit-e.com/teststuff/please_wait.php

The box that appear is actaully semi-transparent and appears over the top of what is already on the page. This example doesn't actually retrieve anything, i just use the sleep() function to puase the script as if i was output a large amount of data.

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

that is very very cool

any chance of getting a quick look at the source?
that could, in effect, negate the need for me to do what i described earlier by effectively giving MySQL time to execute

or a lil' pseudo code would be nice

i didnt even know there was a sleep() function :roll:
Mal
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

<html> 
<head> 
<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<script language=JavaScript> 
function getPageItem(itemID) 
&#123; 
    if (document.getElementById) 
    &#123; 
        return document.getElementById(itemID); 
    &#125; 
    
    if (document.all) 
    &#123; 
        return document.all&#1111;itemID]; 
    &#125; 

    return null; 
&#125; 

<!-- 
function slUpdateSpan(newHtml) 
   &#123; 
   var span_obj = getPageItem("idUpdateableSpan"); 
                if (span_obj) 
                &#123; 
                    if (span_obj.style.display != "inline") 
                    &#123; 
                        span_obj.style.display = "inline"; 
                    &#125; 
                    span_obj.innerHTML = newHtml; 
                &#125; 
            &#125; 
            function killUpdateSpan() 
            &#123; 
                var span_obj = getPageItem("idUpdateableSpan"); 
                if (span_obj) 
                &#123; 
                    span_obj.style.display = "none"; 
                &#125; 
            &#125; 
            //--> 
            </script> 
</head> 

<body> 
<div id="idUpdateableSpan" 
             style="position: absolute; 
                    top: 40%; left: 35%; 
                    width: 30%; 
                    height: 80px; 
                    filter:alpha(opacity=80); 
                    -moz-opacity:80%; 
                    margin:0; 
                    padding:15px; 
                    background-color:#eee; 
                    border:1px solid #333; 
                    text-align: center; 
                    z-index:1000; 
                    display:none; 
                    cursor:default; 
                    "></div> 
<script language=JavaScript> 
<!-- 
   slUpdateSpan("Reading Contents of Database...<br><br>"); 
//--> 
</script> 

<? flush(); sleep(5); ?> 

<script language=JavaScript> 
<!-- 
   slUpdateSpan("Formtting results...<br><br>"); 
//--> 
</script> 

<? flush(); sleep(5); ?> 
                
<script language=Javascript> 
        <!-- 
        killUpdateSpan(); 
        //--> 
</script> 

<? echo "here's the data you wanted"; ?> 

</body> 
</html>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

thank you i will definitely rip apart that script and see what i can come up with and give you a shout to look at.

I know for a fact i could do exactly what i wanted from within flash, but i dont know how many people visit macromedia.com but that site uses the sort of thing i describe and the loading times are an absolute nightmare for doing what effectively PHP could do in less than a second.

Also atm im on a 1.2ghz machine at work which ok, its no good by todays standards, but for the web its like a bullet, and yet flash brings the PC to a gringing halt (try moving your mouse over a complex flash anim, "jilt me some more please!!!")

Just my thoughts anyway
anyone else

thanks bech100, always helpful as usual
Post Reply