Blogs Hub

by AskGif | Aug 30, 2019 | Category :coding

Implementing Jquery Timeago Using PHP.

Implementing Jquery Timeago Using PHP.

<p>Nowadays timeago is the most important functionality in social networking sites, it helps to update timestamps automatically. Recent days I received few requests from askgif readers that asked me how to implement timeago plugin with dynamic loading live data using PHP. In this post, I am just presenting a simple tip to implement timeago in a better way.</p> <p>&nbsp;</p> <p>Why Live Query</p> <p>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.</p> <p>&nbsp;</p> <p>Code</p> <p>Contains javascipt code. $(this).timeago()- here this element is referred to timeago class selector of the anchor tag.</p> <pre class="language-markup"><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.livequery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.timeago.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $(".timeago").livequery(function() // LiveQuery { $(this).timeago(); // Calling Timeago Funtion }); }); &lt;/script&gt; //HTML &amp; PHP Code &lt;?php $time=time(); // Current timestamp eg: 1371612613 $mtime=date("c", $time); // Converts to date formate 2013-06-19T03:30:13+00:00 ?&gt; You opened this page &lt;a href='#' class='timeago' title="&lt;?php echo $mtime; ?&gt;"&gt;&lt;/a&gt;</code></pre>

read more...