Page 1 of 1
real-time output from MySQL
Posted: Wed Apr 14, 2004 7:51 am
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
Posted: Wed Apr 14, 2004 8:07 am
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
Posted: Wed Apr 14, 2004 8:11 am
by malcolmboston
Thank you bech
That looks promising........
Posted: Wed Apr 14, 2004 8:17 am
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
Posted: Wed Apr 14, 2004 8:21 am
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
Mal
Posted: Wed Apr 14, 2004 8:22 am
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)
{
if (document.getElementById)
{
return document.getElementById(itemID);
}
if (document.all)
{
return document.allїitemID];
}
return null;
}
<!--
function slUpdateSpan(newHtml)
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
if (span_obj.style.display != "inline")
{
span_obj.style.display = "inline";
}
span_obj.innerHTML = newHtml;
}
}
function killUpdateSpan()
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
span_obj.style.display = "none";
}
}
//-->
</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>
Posted: Wed Apr 14, 2004 8:27 am
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