-4

I want to get the count of visits from current IP address in last 2 minutes. This is the code I have tried, but the result is always zero. Screen shot of my table is attached. I have tried without prepared statement, it is also returning zero

<?php

$ip=$_SERVER['REMOTE_ADDR'];

$stmt = $con->prepare('SELECT * FROM visitors_activity where ip=? and visit_time > date_sub(now(), interval 2 minute) ');
$stmt->bind_param('s',$ip); 
$stmt->execute();
$result = $stmt->get_result();

echo $result->num_rows; 

Screenshot of my table:
Screenshot of my table

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Midhun S
  • 1
  • 2

1 Answers1

0

With the help of tips from you, i got the answer for my question


$timestamp=date('Y-m-d H:i:s'); 

$ip=$_SERVER['REMOTE_ADDR'];   



$stmt = $con->prepare('SELECT * FROM visitors_activity where ip=? and visit_time > date_sub(?, interval 2 minute) ');

$stmt->bind_param('ss',$ip,$timestamp); 


$stmt->execute();


$result = $stmt->get_result();

echo $result->num_rows;
Midhun S
  • 1
  • 2