Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Search DB every X seconds (no reload) - how??
Old 07-08-2006, 10:57 AM Search DB every X seconds (no reload) - how??
Junior Talker

Posts: 1
Name: Sean Berg
Trades: 0
Hi all.

I'm having a problem here. I want a script to search one field on a mysql database every 2 or 3 seconds. I need it to do this without reloading the page.

I've searched around and can't seem to find an answer. Tried using sleep(); function, but it's not working.

Here's what I tried so far:

Code:
//search the database:
$result = mysql_query("SELECT * FROM partidas WHERE id='$id_do_jogo' ",$connect);

$salazar = mysql_fetch_assoc($result);

//what's in the guest column?
$jogador_dois = $salazar['guest'];
    
//oh, nothing? than we...        
while(is_null($jogador_dois)) {

//...print this out:
     echo "<br>Column value is 0. Trying in another 2 seconds.";

     //Wait 2 seconds and try again.    
     sleep(2);
}

//Or if it is NOT null:
echo "Value different from zero!";
exit();
Any ideas how I could get the script to print out the line "Column value is 0..." and then it tries looking at the database again?

Any help is welcome and apreciated.
seanberg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-08-2006, 08:35 PM Re: Search DB every X seconds (no reload) - how??
Webmaster Talker

Posts: 626
Trades: 0
I don't think you can do that with PHP. PHP is executed before the page loads and therefore my understanding is there is no way to do anything dynamically with php after is has written to the page.

You will probably have to use a different language
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 07-08-2006, 09:26 PM Re: Search DB every X seconds (no reload) - how??
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The example you show would only spit out the page after it finished the sript execution displaying multiple instances of the line "<br>Column value is 0. Trying in another 2 seconds." until it finally escaped the while() loop.

The best solution for you is to use AJAX.
http://www.webmaster-talk.com/javascript-forum/52934-round-up-of-90-ajax-tutorials.html

Look at the Client-Server Communications tutorials.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-09-2006, 08:31 PM Re: Search DB every X seconds (no reload) - how??
reli4nt's Avatar
Extreme Talker

Posts: 168
Location: New York
Trades: 0
PHP is server side script. It cannot execute once it's reached the clients browser with out going back to the server. Javascript is what is needed here. Under AJAX I am certain there are hundreds of scripts avaibale that can manage this.
__________________

Please login or register to view this content. Registration is FREE

Designing the world we live in.
Defining the terms we live by.
reli4nt is offline
Reply With Quote
View Public Profile Visit reli4nt's homepage!
 
Old 07-10-2006, 03:45 AM Re: Search DB every X seconds (no reload) - how??
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Still if you implement ajax you will have to write a simple php script which receives an argument, searches the DB and echoes the output.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Search DB every X seconds (no reload) - how??
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64507 seconds with 12 queries