displaying results each...

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
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

displaying results each...

Post by Jose Arce »

Hi again..while runnig several process, with while, how can i display the results soon as one is finished, without wating untill the others are finished?
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

if you have an echo $variable; in the while loop, everytime it comes to that, it'll echo out the value...
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

thx!

i do have an echo $variable...but it keeps waiting untill the whole loop are finished
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

you may need to use print instead of echo with while.. print $variable;
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

i'll check...thx!

-------------------------------------------------
It's not working :(
-------------------------------------------------
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

echo and print are basically the same thing. The only difference is that print can be called using a variable function.

So there's really no difference between,

Code: Select all

print $variable;
// and
echo $variable;
Mac

PS. If it's not working post some code so that we can help a bit better.
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

i figured there wasn't much of a diff. but looking at the manual for while, it had print so i was think it might interact differently in that respect. otherwise, i wouldn't see why it would wait until the end.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Code: Select all

while (conditions) {
  echo $variable;
}
and

Code: Select all

while (conditions) {
    print $variable;
}
do the same thing. I think what he meant was he had something like:

Code: Select all

while (conditions) {
    $variable .= something;
}
echo $variable;
which is why it would only echo at the end.

Mac
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

exactly. :mrgreen:
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

twigletmac wrote:

Code: Select all

I think what he meant was he had something like:
їcode]while (conditions) {
    $variable .= something;
}
echo $variable;
which is why it would only echo at the end.

Mac
I mean exactly the same...so..echo at the end fo the while?
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

actually...what i really mean goes like this:

Code: Select all

while(conditions) {
                 $anotherprocess
                 if ($anotherprocess) {
                 HERE GOES THE ECHO OR PRINT?
                 }
}
OR HERE?
so thats the deal...hope u can help me
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you want the information to display each time the loop goes round:

Code: Select all

while(conditions) { 
    $anotherprocess; 
    if ($anotherprocess) { 
        echo $variable; 
    } 
}

If you want to put all the information into one long string and echo it once the loop is finished:

Code: Select all

$variable = '';
while(conditions) { 
    $anotherprocess; 
    if ($anotherprocess) { 
        $variable .= $info; 
    } 
}
echo $variable;
Mac
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

it's not workin for me...:(...i guess webservers hate me jeje...
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

Jose Arce wrote:it's not workin for me...:(...i guess webservers hate me jeje...
no, i've had the same problem.... and i'm not sure there is a work around. for example i'll do a really complex MySQL query that ends up returning a thousand or so results. none of the results will show up until they are all finished, then they are all thrown to the page.

it may be a long shot, but you may see what ticks do. they are designed to execute every nth time through a loop... not sure if you could set n=1 and have the tick print your stuff.... it's worth looking into at least.

http://www.php.net/manual/en/control-st ... eclare.php
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

ok...seems very nice, but a bit complex, maybe someone should give us a better explanation of ticks :D
Post Reply