+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Refreshing - mysql query instead of page

  1. #1
    Join Date
    Nov 2006
    Posts
    109

    Default Refreshing - mysql query instead of page

    I've got need for a page to keep checking the mysql db at a regular interval, basically as a way for the page to await my input to perform a task. I've been able to accomplish this by having a query performed and then, if the value is one type to simply refresh the same page (thus iniciating a new query) and check for an update again.

    The problem is with the html page's constant flicker as it refreshes each time. Is there a way I could have just the db query refresh? And leave the html alone so it doesn't flicker?

  2. #2
    Join Date
    Mar 2007
    Location
    Tucson, AZ
    Posts
    173

    Default Re: Refreshing - mysql query instead of page

    hmm.. offhand i'd suggest using javascript and just tagging whatever you wanted to change to update that component..
    Michael Krotchie - REALTORŪ - Coldwell Banker Residential Brokerage, NRT LLC
    6970 N. Oracle Road, Suite 100
    Tucson, AZ 85704
    520.404.4996 -- Mobile
    520.544.4545 -- Office

    Tucson Real Estate | Tucson Real Estate Blog

  3. #3
    Join Date
    May 2007
    Posts
    162

    Default Re: Refreshing - mysql query instead of page

    Javascript is probably the way to go as Michael indicates. Look into doing an XMLHttpRequest to get the data. That way you can just refresh the part of the page you need and not the whole thing.

    Do some research on AJAX. If that's too much for you there might be an easier way we could help identify if you give a more detailed description of the problem.

  4. #4
    Join Date
    Nov 2006
    Posts
    109

    Default Re: Refreshing - mysql query instead of page

    Well, maybe it is time I learn Javascript - or hunt for a script on a forum. I've been wanting to do that anyway.

    I started researching XMLHttpRequest. That might be what I need. Refreshing "part of the page", just the mysql query, would solve the problem.

    I came across two intersting expressions too, in an article talking about building APIs

    _ You won't be able to please everyone
    _ Aim to displease everyone equally

    and

    _Code should read like prose

    I think I'll adapt the first, but will have to leave the second for the next lifetime :-)

  5. #5
    Join Date
    Nov 2006
    Posts
    109

    Default Re: Refreshing - mysql query instead of page

    Now I'm looking at Wikipedia's write up on AJAX. MMMMMMMMMMM --- input ----- mmmmmmmmmm

  6. #6
    Join Date
    Nov 2006
    Posts
    109

    Default Re: Refreshing - mysql query instead of page

    ooh -- oooh
    " In this tutorial, I will show you how to utilize AJAX to automatically poll your MySQL database for updates without your visitors needing to click anything. The final code will silently check for updates, and update the page if (and only if) new updates are found."
    http://www.codewalkers.com/c/a/Misce...AJAX-Tutorial/

    Thanks all, looks like I'm on the right track

  7. #7
    Join Date
    May 2007
    Posts
    162

    Default Re: Refreshing - mysql query instead of page

    Also be careful your don't create too much load on your server if you have a lot of clients hitting the server. Success could kill you if your clients are pinging the server too frequently. Also, consider if there is no activity for a while you don't need to keep checking the server. One open browser could consume a lot of resources.

    If you only expect a handful of users at first, don't worry about this. Just get it working first. Good luck.

  8. #8
    Join Date
    May 2007
    Location
    far east
    Posts
    690

    Default Re: Refreshing - mysql query instead of page

    ajax, but be careful on interval you set for refresh. a lower interval can kill your server if you have big db

  9. #9
    Join Date
    Nov 2006
    Posts
    109

    Default Re: Refreshing - mysql query instead of page

    I'm getting a bit bogged down here. I'm figuring out the ajax part but the javascript and the time refresh is getting me.
    The first thing my little script needs to do is access the db constantly (I currently have it set at every ten seconds using meta refresh).

    I haven't seen any ajax scripts that do this but the following link with javascript made for ajax seems close. It is javascript though, and I can't even get started with it. Does it look like something that would query and return the values from a mysql db (using a php script ) ?
    http://www.servletsuite.com/servlets/ajaxtimertag.htm

    Part of its code is like this -

    <script language="JavaScript" src="cjajax.js"></script>

    <%@ taglib uri="taglib.tld" prefix="a" %>

    <a:AjaxTimer id="i1" url="newContent.jsp" timeout="10" handler="myHandler">
    and it says about it
    "In this example your file newContent.jsp will be requested each 10 seconds." It sounds like if I replace newContent.jsp with getmysqldata.php the query would be done evry ten seconds, just what I need.

    I tried it but the syntax and such has me baffled. For instance, why does it place opening javascript tags in front of src="cjajax.js" and then close it immediately? And the webpage describing it doesn't say what src="cjajax.js" is supposed to be? Can someone please, get me started with this? Thanks

  10. #10
    Join Date
    Nov 2006
    Posts
    109

    Default Re: Refreshing - mysql query instead of page

    I think I am gaining -
    Can someone tell me if the following code transition from javascript to php is properly done (or not even close)?


    if(xmlHttp.readyState==4)
    {
    xmlHttp.open("GET","getmymysqldata.php",true);
    xmlHttp.send(null);
    document.myForm.pause.value=xmlHttp.responseText;

    <? if($out_of_sequence_protect == 1){echo 'OOSP On ';

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts