javascript - Auto refresh/load data only if new data inserted or updated -
in case, create auto refresh after x seconds. want create refresh when new info inserted or updated.
here script.
refresh.php
<script src="jquery-1.4.js"></script> <script> $(document).ready(function() { $("#responsecontainer").load("refreshnow.php"); var refreshid = setinterval(function() { $("#responsecontainer").load('refreshnow.php?randval='+ math.random()); }, 1000); }); </script> <div id="responsecontainer"></div>
refreshnow.php
<?php $query = mysqli_query($connection,"select * `table`"); $rows = mysqli_num_rows($query); ?> <table style="background:#f0f0f0;" border=1 style="border-collapse:collapse"> <tr> <th>name</th> <th>job</th> </tr> <tbody> <?php while($result = mysqli_fetch_array($query)){ echo "<tr>"; echo "<td>".$result["name"]."</td>"; echo "<td>".$result["job"]."</td>"; echo "</tr>"; } ?> </tbody>
so, possible load new info automatically when new info inserted or updated without refresh after x seconds?
if want utilize existing code, add together column in mysql table (if got config or settings table, easyer, if not advertisement timestamp each record insert) value time(), updates timestamp in database each time row inserted/modified. query like:
"select timestamp_column `settings_table` order timestamp_column limimt 1" if ($result["timestamp_column"]+1000>=time()){ //do refreshnow.php code here }
hope helps, cheers
javascript php jquery html ajax
No comments:
Post a Comment