Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
PHP
$cookie_FromVal = '2015-10-28 12:00:00am';
$cookie_ToVal = '2015-10-28 12:00:00am';

$conn = new mysqli($hostname,$username,$password,$database);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
// get data and store in a json array

$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
Posted
Updated 27-Oct-15 22:02pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900