Real Estate Forums

Coding HTML, ASP, PHP, JAVA MYSQL and more. All coding questions should be asked here.

Reply
 
Thread Tools Display Modes
Old 05-11-2007, 05:34 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
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?
Reply With Quote
Old 05-11-2007, 10:44 PM
mkrotchie's Avatar
mkrotchie mkrotchie is offline
Real Estate WebMaster
 
Join Date: Mar 2007
Location: Tucson, AZ
Posts: 173
mkrotchie is on a distinguished road
Send a message via AIM to mkrotchie Send a message via Yahoo to mkrotchie
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
Reply With Quote
Old 05-11-2007, 10:59 PM
Calculator Calculator is offline
Real Estate WebMaster
 
Join Date: May 2007
Posts: 162
Calculator is on a distinguished road
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.
Reply With Quote
Old 05-12-2007, 09:11 AM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
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 :-)
Reply With Quote
Old 05-12-2007, 09:30 AM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
Default Re: Refreshing - mysql query instead of page

Now I'm looking at Wikipedia's write up on AJAX. MMMMMMMMMMM --- input ----- mmmmmmmmmm
Reply With Quote
Old 05-12-2007, 10:17 AM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
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
Reply With Quote
Old 05-12-2007, 11:35 AM
Calculator Calculator is offline
Real Estate WebMaster
 
Join Date: May 2007
Posts: 162
Calculator is on a distinguished road
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.
Reply With Quote
Old 05-14-2007, 11:55 AM
gibex's Avatar
gibex gibex is offline
Uber Real Estate Webmaster
 
Join Date: May 2007
Location: far east
Posts: 539
gibex is on a distinguished road
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
Reply With Quote
Old 05-14-2007, 05:59 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
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
Reply With Quote
Old 05-14-2007, 11:04 PM
RESynergy RESynergy is offline
Real Estate WebMaster
 
Join Date: Nov 2006
Posts: 109
RESynergy is on a distinguished road
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 With Quote
Reply


Thread Tools
Display Modes

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



For our members

Main Sections

IDX Coverage Areas

Spiders Welcome

All times are GMT -7. The time now is 01:01 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.