Reputation: 1657
I am trying to return the data that is true from my database using this mysqli statement
$resulttwo = mysqli_query($link, "
SELECT
*
FROM
Events
WHERE
time >= '%$lasttime%'");
The variable "lasttime" is an float of a really high value. The numbers in the database are all below below this number. However, when I use this statement, it returns all rows in the database. I do not understand why using this comparison yields incorrect results. Is there something that I am missing?
Upvotes: 0
Views: 67
Reputation: 703
'%$lasttime%'
is a string, that equates to zero when used in a numeric comparison. time
may be a string column, as you say, but gets successfully cast numeric when you use >=
. if $lasttime equaled 12345 and $time equaled 54321, then the comparison is 54321 >= '%12345%'
which equates to 54321 >= 0
, as '%12345%'
doesn't get converted to an int.
To test:
select '%12345%' = 0, '12345' = 0
returns TRUE (because that's a non-numeric string, whose value is 0) and FALSE (because that string can be converted to 12,345, and not equal to 0).
I have no idea why you want to use wildcards in this query.
Upvotes: 1