I want to check for new post in database in every 10 seconds and fetch it and show it on homepage. the problem i'm facing is the query is again fetching those post only which are already on homepage...how to tell query to fetch above from last id for e.g if last post in database with id is 25 so how to tell query to fetch above 25 and show it. thanks in adavance
here is Ajax Code
<script type="text/javascript">
var autoLoad = setInterval(
function ()
{
$('#load_post').load('load_post.php').fadeIn("slow");
}, 10000); // refresh page every 10 seconds
</script>
<body>
<!--append load-post.php echo value here-->
<div id="load_post"></div>
</body>
here is php code of load_more.php
<?php
include_once('config.php');
$sql = mysql_query( "SELECT * FROM post LIMIT 2 DESC" ) or
die(mysql_error().' Error loading data.');
$num_post = mysql_num_rows($sql); // count the number of rows
// check if there is data
if( $num_post ) {
//this contains data to load into a page.
} else {
echo '<p>There are no added post yet, please try to add to start
sharing.
</p>';
} ?>
Use it like this
SELECT * FROM post WHERE id > $id ORDER BY datetime DESC
Here, $id
is the id of the last post
EDIT
If you use datetime, then you should use
SELECT * FROM post WHERE datetime > $datetime ORDER BY datetime DESC
$datetime
is the last fetched datetime
** Try this query **
it is get only last id of your tabel
SELECT * FROM post WHERE id =(SELECT MAX(id) FROM post));