Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7516663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:12:17+00:00 2026-05-30T01:12:17+00:00

Let say i have 15 or more posts in one page. The code inside

  • 0

Let say i have 15 or more posts in one page. The code inside the while loop look like this

 <div class="post" id="<?php echo $postID?>">

    <h1><?php echo $title;?></h1>

    <div class="postmeta"> 
posted by <?php echo $author;?> , <?php echo timeAgo($postDate);?></div>
    </div>

this is just an a example ! So timeAgo() function convert the unix timestamp 1329569847 to human time 11 mins ago. And how to make it synchronize in real time with ajax I mean after 5 mins to change to 16 mins ago,after 4 mins to change to 20 mins ago and that to effect all posts.


So i managed to make it work thanks to chenio and TheShellfishMeme (beer).

And this is the code that do the magic

<span class="timestamp" id="5" postdate="1329576793"></span><br/>

<span class="timestamp" id="8" postdate="1329576795"></span><br/>


<script>

updateTimestamps();
setInterval(updateTimestamps, 60000);

function updateTimestamps(){
    $(".timestamp").each(function(i){

        var timestamp = $(this).attr("postdate");
var postID = $(this).attr("id");

$.ajax({
type: "POST",
url: "myURL",
data: "postID="+ postID +'&timestamp=' + timestamp, 
cache: false,
success: function(html){

$(".timestamp#"+postID).html(html);

}
});




    });
}
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:12:19+00:00Added an answer on May 30, 2026 at 1:12 am

    I’d use data attributes like here http://jsfiddle.net/rXFnn/ to add the unix timestamp to a span inside the div which is meant to contain the ‘time ago’ string.
    Then you port your timeAgo logic over to javascript and update it every minute using setInterval.

    No need to do AJAX for something that simple, but note that the example below uses jQuery.

    For completeness, here is the code again:

    <div class="postmeta"> 
        posted by Foo , <span class="timestamp" data-timestamp="1329573254200"></span> ago
    </div>​
    
    <script>
    updateTimestamps();
    setInterval(updateTimestamps, 60000);
    
    function updateTimestamps(){
        $(".timestamp").each(function(i){
            var timestamp = $(this).data('timestamp');
    
            // Put your time ago logic here
            var timeAgo = timestamp;
            $(this).text(timeAgo);
        });
    }
    </script>
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, let's say I have this code (VB.Net): Sub Main() dim xxx as string
Let's say we have @posts = Post.published.per(10).page(params[:page]) somewhere in our controller. Later on we
Let's say I have 3 or more peers connected to the same WiFi Access
I have let's say 2 (but they'll become more in the future) fully decoupled
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let say I have an array like: Array ( [0] => Array ( [Data]
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
let say i have a page , and i want to allow 3rd party
Let say I have a sheet in with columns Customer and CreatedDate with lots
Let say i have some words AB, AAB, AA. AB is not a prefix

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.