0

I am attempting to query a db row every n seconds to see if a value has changed, then based that value I want to build a class that I can apply to a div in my page.

I can currently echo out the slide number, i have this

echo("The current slide number is: ".$currentSlideNbr);

but am not sure how to query every n seconds and then add .$currentSlideNbr to my class name with jquery

Thanks in advance

beryllium
  • 29,669
  • 15
  • 106
  • 125
Ichimonban
  • 97
  • 1
  • 12
  • See my answer here, it is almost the same question . http://stackoverflow.com/questions/9030272/notification-when-new-record-is-added-in-database-php-jquery/9030340#9030340 – xdazz Jan 27 '12 at 08:22
  • Possible duplicate : http://stackoverflow.com/questions/3648082/ajax-auto-update or http://stackoverflow.com/questions/4802973/how-to-update-the-page-without-refresh – Tudor Jan 27 '12 at 08:29

1 Answers1

1

here's a simple javascript example that will trigger every n second(s)

    var n = 1000; // 1 sec
    var interval = setInterval(function() {
        $.ajax({
            url: 'your url',
            method: 'get',
            success: function(data) {
                $("#someelement").addClass(data);
            }
        });
    }, n);

if you want to stop the process at any time you can do

clearInterval(interval);

not that data should only contain the classname you like to add. So not

echo("The current slide number is: ".$currentSlideNbr);

but

echo($currentSlideNbr);
Manuel van Rijn
  • 10,170
  • 1
  • 29
  • 52
  • a couple questions, your url = my database address? and data = .$currentSlideNbr? – Ichimonban Jan 27 '12 at 08:32
  • maybe this will help, this is what i am using to query the db currently, $query = "SELECT slide_nbr FROM `skdemo`.`demo` WHERE demo_name = 'culture';"; $result = $mysqli->query($query); $row = $result->fetch_row(); $currentSlideNbr = $row[0]; $result->free(); $mysqli->close(); – Ichimonban Jan 27 '12 at 08:35
  • your url is you php file, which queries the database to echo the slide number – Manuel van Rijn Jan 27 '12 at 08:53