change page 10 query in 10 seconds

2

I have a page that lists all my events from the event table ( tbl_eventos ). I want to list all the events of the first week of the year, past 10 seconds, list all events in the second week of the year, and so on.

In my events table I have the following fields: id_evento; nome; data

To query, I'm using php and mysql . I'm thinking of using ajax, but I do not know how to do it to update the content every 10 seconds and how to send the date I'm going to look for.

    
asked by anonymous 10.02.2015 / 11:51

1 answer

3

Assuming you use jQuery.

Javascript:

jQuery(function(){

    var semana = 0;

    var itv = window.setInterval(function(){
        jQuery.get("consulta.php?semana="+semana, function(data){
            jQuery("#container").html(data);
        });

        semana++;

    },10000);
});

PHP:

/*Supondo que você já possua a conexão com o banco de dados*/

$semana = $_GET["semana"];

/*Supondo que a variável $semana seja 0, a consulta irár retornar todos os registros da primeira semana do ano, independente do ano. Para restringir, utilize por exemplo, 'AND YEAR(data) = 2014'*/
$query = mysql_query("SELECT * FROM tbl_eventos WHERE WEEK(data) = {$semana}");

while ( $row = mysql_fetch_object($query) ){
    echo $row->id_evento . " - " .  $row->nome . " - " . $row->data . "<br>";
}

I did not test, but should work.

    
10.02.2015 / 12:12