php - How to check if there is an added record on the database -


i have here index.php. contains layout , php code inside it. want know if there new record on database. research needs refreshed. tried javascript auto refresh , whole page refreshes if there new records table automatically show new record. problem how know if there changes. able show if there update on database through refresh not able notify if there changes. want put notification if there new records. want know how check if there new records on database. here code.

<div class="panel panel-default">     <div class ="panel-body">       <!-- table of reports -->     <div align = "center" style = " font-size: 9000px">         <table class="table table-striped" name = "report">             <thead>                 <tr align = "center"class = "active" >                      <td class  = "theads" >id</td>                     <td class  = "theads" >message</td>                 </tr>             </thead>              <!--start of php code -->             <?php                $page=1;//default page             $limit=10;//records per page             $start=0;//starts displaying records 0             if(isset($_get['page']) && $_get['page']!='')             {                 $page=$_get['page'];             }                 $start=($page-1)*$limit;                  //get total records (you can use mysql count function count records)                 $query=mysql_query("select report_id reports");                 $rows=mysql_num_rows($query);                  $query=mysql_query("select * reports order datetime desc limit $start, $limit");                   if(mysql_num_rows($query)>0)                 {                     while($row=mysql_fetch_array($query,1))                     {             ?>              <tbody>                 <tr class = 'active'>                 <td align = 'center'><?php echo $row['report_id'] . "<br>";?></td>                 <td align = 'center'><?php echo $row['message'] . "<br>";?></td>                 </tr>             </tbody>                  <?php                     }                 }             ?>         </table>      </div>      </div> </div> 

if want notification system on client side can create cookie latest created date , check if created date greater date of cookie count rows having greater date cookie's value.

if want on server side have save last seen created date in database table , above process.

$query=mysql_query("select * reports order datetime desc limit $start, $limit"); if(isset($_session['chk'])) {     $sql=mysql_query("select count(*) new_record reports datetime>$_session['chk']");     $count=mysql_fetch_array($sql);     $new_record=$count['new_record']; // new records }  if(mysql_num_rows($query)>0){$i=0; while($row=mysql_fetch_array($query,1)){if($i==0){$_session['chk']=$row['datetime'];$i++;} ?> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -