$cookie_FromVal = '2015-10-28 12:00:00am';
$cookie_ToVal = '2015-10-28 12:00:00am';
$conn = new mysqli($hostname,$username,$password,$database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$stmt = $conn->prepare("SELECT username,address,country FROM Users WHERE UpdatedDate BETWEEN ? AND ?");
echo "Binding1 " .$cookie_FromVal . "";
echo "Binding2 " .$cookie_ToVal . "";
$stmt->bind_param('is', $cookie_FromVal, $cookie_ToVal);
$stmt->execute();
$result = $stmt->get_result();
$users = null;
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$usersToday[] = array(
'username' => $row['username'],
'address' => $row['address'],
'county' => $row['country']
);
$users = $usersToday;
}
} else {
echo "0 results";
}
mysqli_free_result($result);
$conn->close();
header("Content-type: application/json");
echo "{\"data\":" .json_encode($users). "}";
Hi have the above source code for getting user details from mysql for
particular range of UpdatedDate datetime FromDate and toDate
If I set $cookie_FromVal and $cookie_ToVal as different
datetime the above code works fine without an error ,
but If I set both values as equal it returns all the
rows inside the database...
say if I set $cookie_FromVal=$cookie_ToVal='2015-10-28 12:00:00am'
it returns all rows which is lessthan '2015-10-28 12:00:00am'
and also which is equal to '2015-10-28 12:00:00am' irrespective of query.
This occurs only if database have date values lesser or equal to given dates
and both the dates $cookie_FromVal and $cookie_ToVal are equal
Guys please help me to sort out this issue.
Thanks
Sreeyush