Re: Looping through output
- From: lanmind <LANMIND01@xxxxxxxxx>
- Date: Mon, 1 Jun 2009 12:01:46 -0700 (PDT)
On Jun 1, 1:58 am, Gordon <gordon.mc...@xxxxxxxxxxxx> wrote:
On May 31, 7:28 pm, Lan Mind <LANMIN...@xxxxxxxxx> wrote:
So I'm outputting XML and I'm trying to output XML continuable in a
loop while a condition is true. Here is what I have:
$originalquestion= mysql_query("SELECT question, answer, id from
answers WHERE id='{$_SESSION['userid']}'");
$row = mysql_fetch_array($originalquestion);
while ($row['id']<=500)
{
header("Content-type: text/xml");
echo '<person>';
echo "<result>" . $row['id'] . "</result>";
echo "</person>";
}
So I'm outputting XML and I'm trying to output XML continuable in a
loop while a condition is true. Here is what I have:
CODE
$originalquestion= mysql_query("SELECT question, answer, id from
answers WHERE id='{$_SESSION['userid']}'");
$row = mysql_fetch_array($originalquestion);
while ($row['id']<=500)
{
header("Content-type: text/xml");
echo '<person>';
echo "<result>" . $row['id'] . "</result>";
echo "</person>";
}
When this script is run I'm getting a "junk after document element"
error. I believe since a new header is being started after the XML
root element's ending tag it's generating this error. I've never tried
looping through output like this and I don't know if it's possible. I
tried using PHP's flush() function in combination with the
time_nanosleep() function to send the XML output then start a new
output but it didn't work. Is it possible for PHP to keep outputting
DB query results?
I really can't tell for sure what you're trying to do, but from what
I've been able to gather from reading the other replies it sounds like
you're trying to do some kind of AJAX updating based on a database
field changing. In this case a better approach would probably be to
use AJAX to poll the server every few seconds (but not too often as it
will put load on the server and client machines) to get the current
value. In this case all your PHP script would need to do is spit out
an XML or JSON response to a query and not need to worry at all about
how the database might be changing during the execution of the script.
Hello Gordan,
Yes I am updating the client's browser with AJAX. I didn't know how a
server would act with so many requests but now I see I need to be
careful about it. Does anybody know of good articles detailing HTTP
requests and such? I'll use javascript to send a request every few
seconds. Thank you.
.
- References:
- Looping through output
- From: Lan Mind
- Re: Looping through output
- From: Gordon
- Looping through output
- Prev by Date: Re: Executing PHP files on remote web server
- Next by Date: Re: Executing PHP files on remote web server
- Previous by thread: Re: Looping through output
- Next by thread: Help with read() function
- Index(es):
Relevant Pages
|