Hey all,

I have a script that pulls a MySql database to see if there are any jobs for it to do. The jobs get inserted via a PHP script based on what the user inputs.

There is an html table that is generated by PHP that shows the jobs, there status, start and end time (you get the idea) from MySql. What I would like to do here is have the html table auto update every 15 seconds or so as long as there is a job in progress (should be a simple if statement) but I do not want the entire page to reload.

What my issue is that I have no idea where to start to get something like this done. At the present time the table is generated but never changes unless the page is reloaded.

Is this even possible to do this with PHP?

    Getting the updated info back to the browser is pretty much the same as presenting information in the first place, and can easily be handled by PHP.

    However, to accomplish this, you will need the javascript function setInterval to make this happen every 15 seconds. You will also need XHR, xml http request, commonly called ajax.

    You can deal with this yourself, or use one of many javascript libraries, e.g. jquery, prototype, yui

      are you able to provide an example?

      and this can be used to only refresh the Html table and not the entire page?

        It can be used to do anything. You send a request to the server, you get some information back (hopefully), you do stuff with that information. Ditch it, append it someplace, overwrite something else... or replace everything in the page if you'd like. The only thing XHR doesn't handle is file upload, but that can be dealt with by trickery.

        Example seems kind of pointless since it would depend on what framework you chooce to use. But it might look something along these lines.

        iAmCalledOnSomeEvent() {
        	var a = new ajax();
        	a.rp = '/serversidescripttocall.php';
        	a.post = 'someelement=this&otherelement=that';
        	a.success = function(response) {
        		alert('hey, i got this: ' + response);
        	}
        	a.startRequest();
        }

          hrm.. this is a problem.

          that fact that i gotta call a php file is a problem. At this point everything is in one php file with functions. the function that displays the HTML table is when the customer does not issue any commands or visits the pages for the first time.

          is there a way to cycle through the a section of php code every so soften or will i have to seperate the file that generates the HTML table?

            Once you call the php script, you can, as usual, require/include whatever other files you like, call functions as normal etc. And as far as the web server is concerned, there is no difference between an XHR and ordinary request.

              Write a Reply...