views:

53

answers:

3

What I am looking into is:-

I do have a search page say index page. and the action file is search.php. when I fire a query search.php will start processing on what I searched.

structure of search.php

  1. it uses $_GET function to retrieve query from index page.
  2. first it will search in MySQL database.
  3. IF yes then display the result from MySQL database.
  4. IF null then do the process to get the result for the query and Insert into MySQL database

what I need is if the query result isn't in the database then it should show a progress message saying "Please Wait We have come across this query first time hence we are updating our database" or something which is suitable.

How do I do it in PHP??

A: 

Use AJAX to communicate asynchronously.

MarcAndreson
+2  A: 

Hello again mathew...

this would be another good candidate for using an ajax request on. you'd load the base page and then fire off the ajax request once it was loaded. then display a message if there was any wait state in play, then replace the message with your search results...

jim

jim
Hi Jim actually I have a tough time to integrate Ajax with PHP. it is very difficult for me like I said previously I am not familiar with Ajax and some areas in JavaScript. how do I fire Ajax request through PHP?? any sample...actually I can get lots of sample script from Internet but the major part is integration between two.
mathew
mathew - this little example seems to cover everything in a basic and informative way: http://php4every1.com/tutorials/jquery-ajax-tutorial/or http://www.queness.com/post/328/a-simple-ajax-driven-website-with-jqueryphp
jim
You don't fire the Ajax request from PHP - it's a call in your JavaScript, which will request a PHP file on the server. Jim's answer will work fine, as long as you're careful.
Stephen Orr
+1  A: 

As the others have mentioned, use AJAX to poll the server and check if the search is done. However, you still need to "end" the first request and spawn the search processing code so the user's browser doesn't just sit there waiting for data.

On the server you can spawn a process that disconnects from the request process like this:

exec('nohup /path/to/script.php > /dev/null &');

You would probably need to pass some parameters to the script indicating what search to do. But by doing it this way, you don't have to worry about browser timeouts.

Brent Baisley