[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Continuously Update mysql query

I have a PHP scrpt that queries a database, and returns the number of records in the query.  The query works.  However, I need to have this number of records updated continuously.  So as other users add records, this counter increases WITHOUT reloading the page.  Any ideas?

I am thinking of something similar to ecommerce sites that as you put a new item in your cart, the counter showing the number of items in the cart increases, even though the page doesn't refresh.

Something similar to what Expert Exchange has for Open Questions and Question History.  The number of open questions is in () next to the Open Question Link.  I want something like that that updates dynamically without refreshing the whole web page.
$query_rs_select = "SELECT * FROM cbacks WHERE assessor_done = 0  AND mid_user = '$user' ";
$rs_select = mysql_query($query_rs_select, $connect_crm) or die(mysql_error());
$row_rs_select = mysql_fetch_assoc($rs_select);
$totalRows_rs_select = mysql_num_rows($rs_select);
 if(!mysql_num_rows($rs_select)) {
 
$upload = 0;
 
} else {
$upload = $totalRows_rs_select;
  
 
}
echo $upload;

Open in new window

0
fastfind1
Asked:
fastfind1
2 Solutions
 
hieloCommented:
>>WITHOUT reloading the page
I strongly suggest you look at the following ajax tutorial:
http://w3schools.com/ajax/ajax_intro.asp

so that you can understand the db example:
http://w3schools.com/ajax/ajax_database.asp

for your purposes, you will need to send periodic ajax requests
0
 
wassa_rCommented:
Use AJAX together with a javascript library like jQuery. You then build a PHP page that simply outputs the number of rows, and do a periodical updater that updates the page every few seconds. It'll look like the page never reloads, and it updates the counter.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now