0
<?PHP
  $result = mysql_query("SELECT depoimento, nome from depoimentos WHERE avaliado = '1'");
  $i = 0;
  while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    $i= $i+1;
    if ($i > 1) {
      printf("<div style='display:none' id='$i'>%s<br><br><i>%s</i></div>", $row[0], $row[1]);
    }else{
      printf("<div style='display:block' id='$i'>%s<br><br><i>%s</i></div>", $row[0], $row[1]);
    }
  }
?>

It is showing only the first result (first result = ($i = 1)). All results after the first($i > 1) it is DISPLAY:NONE. What I need: After 5 seconds the first result disapear (display:none) and the second appears (display:block) and then third, etc...

Its showing coments on the website but it must show only 1 coment per time.

I know it needs javascript but i NEVER used it in my life and im not getting success with my searches on web.

  • 2
    We will not write this for you, you have to do research on your own. Anyway, some tip for the flow - load all messages into JavaScript array and using some interval, display next one every X second. – Pavel Štěrba Feb 14 '14 at 13:46

3 Answers3

0

From my point of view you have to approaches: 1. You send all the rows to the client and you use display:none in css and from javascript using setInterval you display the results 2. You make a ajax and on the server you get different sql queries depending on the request and you display them on the page.

snalkum
  • 16
  • 4
0

You may use Interval in Javascript (Timing Event) for calling the functions after specific time interval

For Example:

   tVar= setInterval(
       function(){
        // Here your function calls 
        // the function here will be called after 3 seconds as 3000 is interval 
            },
        3000);
Zeeshan
  • 858
  • 4
  • 16
  • 30
  • Can you elaborate the question more ?? You want to have mysql query with interval or you fetch the data and need to populate on your page in timing interval ???? – Zeeshan Feb 14 '14 at 15:25
  • In order to update the data you have to use the Javascript code. You should have to use the ajax query in the timer function so that the query is made after a particular interval of time and then on this value you have to populate the new value and remove the previous value using Javascript you may see this link: http://stackoverflow.com/questions/7165395/call-php-function-from-javascript – Zeeshan Feb 14 '14 at 16:06
  • Its the most complicated thing I ever seen. Thank you but i give up.. 2 days trying that and no success and it will require a time to study that I dont have anymore. Thanks man. – user3310429 Feb 14 '14 at 16:13
0

Here you can find a working example of my first option: http://jsfiddle.net/evTnP/1/ I use a global variable but it is only for test purpose:

function displayUsers(nr){
++i;
$(".test").each(function(index, value){
    if(index==i){
     $(this).css("display","block");   
    }
});

 }
var i=0; $(document).ready(function(){

setInterval(displayUsers,5000);
});` 
snalkum
  • 16
  • 4