Timeago Implementation with Jquery and PHP


Timeago is the most important functionality in social networking sites, it helps to updating timestamps automatically. In this post I am just presenting a simple tip to implement timeago in a better way with dynamic loading live data using Jquery and  PHP.



Why Live Query
LiveQuery utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated.

Contains javascipt code. $(this).timeago()– here this element is refers to timeago class selector of the anchor tag.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.livequery.js"></script>
<script type="text/javascript" src="js/jquery.timeago.js"></script>
<script type="text/javascript">
$(".timeago").livequery(function() // LiveQuery 
$(this).timeago(); // Calling Timeago Funtion 

//HTML & PHP Code
$time=time(); // Current timestamp eg: 1371612613
$mtime=date("c", $time); // Converts to date formate 2013-06-19T03:30:13+00:00 
You opened this page <a href='#' class='timeago' title="<?php echo $mtime; ?>"></a>
Please follow and like us:

By Rodney

I’m Rodney D Clary, a web developer. If you want to start a project and do a quick launch,I am available for freelance work.

Leave a Reply

Your email address will not be published. Required fields are marked *