2 votes

Update a section through a query

I need to update a div every second, but this div has a query that has not worked correctly, since it is doing a query to mysql. I don't know if I have to add anything else, since it never loads anything from the BD

      <?php
     include "../config/config.php";
    $id_ticket=7;
     ?>
     <head>

     </head>
     <body>

    <div id="comen">
         <?php


                            $come=mysqli_query($con, "select* from comentario where id_ticket='".$id_ticket."' order  by  fecha_comen desc");
                            foreach($come as $c):?>

                                 <?php
                                 $userb=$c['id_usuario'];
                                 $users=mysqli_query($con, "select * from user where id='".$userb."'");
                                 foreach($users as $u); 
                                 ?>        
                                  <div class="<?php echo $usercss;?>">
                                   <div class="date">
                                        <?php echo $c['fecha_comen'];?>
                                   </div>
                                           <div class="user">
                                              <i class="fa fa-user"></i>
                                               <span class="name">
                                                <?php echo $u['name'];?>
                                                </span>
                                                <span class="type">
                                                 <?php echo $u['email'];?>
                                                 </span>
                                          </div>
                                          <div class="message">
                                               <p> <?php echo $c['comentario'];?><br/>
                                         </div>
                              </div>
                                <?php
                        endforeach; 
                         ?>
     </div>


    <script>
    $(document).ready(function() {
        var refreshId =  setInterval( function(){
        $('#comen').load("comen.php");//actualiza el div
       }, 1000 );

});
</script> 
</body>
 

0voto

The correct way to use the setInterval should be something like the following:

 function refrescar(){
  console.log("funciona");
} 
 <HTML>
    <HEAD>
        <TITLE>Título de la página</TITLE>
        <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
        
    </HEAD>

    <BODY>
        Aquí iría el contenido de la página
    </BODY>
    <script>
$(document).ready(function(){
	var myVar = setInterval(refrescar,1000);
});
</script>
</HTML> 

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X