Continuously Update mysql query

Posted on 2008-11-18
Last Modified: 2013-12-13
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

Question by:fastfind1
    LVL 82

    Accepted Solution

    >>WITHOUT reloading the page
    I strongly suggest you look at the following ajax tutorial:

    so that you can understand the db example:

    for your purposes, you will need to send periodic ajax requests
    LVL 3

    Assisted Solution

    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now