-1

I have an array $d of postcodes, this generates markers of my google map. I want only show markers which were created less than 3 seconds, over 3 seconds will be hidden.

$postcodes = array();
 $diff = array(); // time difference variable
 foreach($stmt as $x){
  //////////////time calculation start////////////////////////////     
        $posts[] = $x['date'];
        $timePosted = new DateTime($posts[] = $x['date']);
        echo 'Time Posted : '. $timePosted ->format("d-m-Y H:i:s");
        echo "</br>";
        date_default_timezone_set('Europe/London');
        $today = date('d-m-Y H:i:s');
        echo 'Current time is : '. $today;
        echo "</br>";      
        $today = new DateTime(date('d-m-Y H:i:s'));
        $interval = $timePosted->diff($today);
         "Difference " . $interval->d. " days ". $interval->h. " hours ".$interval->i." minutes ".$interval->s." seconds ";
        echo "</br>";
        //$diff[] = $interval->h. " hours ".$interval->i." minutes ".$interval->s." seconds ";
        $diff[] = $interval->s;  //last array seconds
/////////////////////time calculation finish here/////////////////////////

  global $postcodes;
 //$postcodes[] = $x['postcode'];  //postcodes
  foreach ($diff as $time => $seconds) {
           echo var_dump($seconds);
           if($seconds >=3){
           echo "larger than 3 seconds<br />";
           }else{
         echo "smaller than 3 seconds.<br />";
        $postcodes[] = $x['postcode'];  //this need to be globle not working yet
           }
        }//time foreach loop finish here


    } /// main foreach loop finish here
  $d=' "'.implode('","',$postcodes).'"'; //postcodes inside $postcode array
user999
  • 53
  • 1
  • 3
  • 9
  • How are you attempting to hide the marker? – geocodezip Mar 20 '16 at 22:06
  • there is a timestamp in my database, $diff array already calculated the time difference, I am trying to make $d hidden after hitting the 3 seconds by setting it false.but now all markers are hidden, but I am sure there must be a way to do this. – user999 Mar 20 '16 at 22:09
  • What is $d? Is it an array of markers or a boolean variable? Please provide a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates the issue. – geocodezip Mar 20 '16 at 22:15
  • @geocodezip thank you for your reply, $d is an array of postcodes which generate all markers for my map, please see the updated code. – user999 Mar 20 '16 at 22:31
  • what to you think setting the array to false/true will do? – geocodezip Mar 21 '16 at 00:03

1 Answers1

0

I can't believe how simple this can be, it turns out I don't need to write this in php at all, I can just do it in SQL all I need is to add date >= now() - INTERVAL 3 second; to my sql statement. Hope this can help someone.

user999
  • 53
  • 1
  • 3
  • 9