I can't seem to get this to work,
Basically, what I want to do is return all the rows in which the column timestamp is more than the variable $timestamp, and the column hit_counter is less than the column max_hits.
Getting the first part to work isn't a problem, but the second part seems to be, as it still fetches rows when hit_counter is more than max_hits.
Here's my code:
$query = "SELECT * FROM links WHERE timestamp >= '$timestamp' AND hit_counter >= 'max_hits' AND overflow = 'NO'";
$result = mysql_query($query);
$size = mysql_num_rows($result);
That seems to return all the correct rows for timestamp, however still continues to select rows where hit_counter is more than max_hits (even though it shouldn't select any at all as >= is more than or equal to), while to inverse >= to <= returns no results, even though mathematically, it's valid.
I think perhaps I'm referencing max_hits as a value incorrectly, as I don't understand why it's working in the first place?
I know my question is a little iffy, so if you need any clarification please, do ask :).
Any answers/help would be greatly appreciated!
UPDATE:
I've updated the query as per the many great answers below, (removing the '' encasing max_hits and changing >= to <= but it still returns rows which are not meant to be included by the query.
Here's a pastebin to my full code: http://pastebin.com/V4vXJr1w
Here's a link to my table structure: https://docs.google.com/spreadsheet/ccc?key=0AoELUDjfbpSXdEUybkgwQmpxUnVCWlZOZnFJdzFaQmc&hl=en_GB
hit_counter >= max_hitsto return? You seem surprised that it's returns results where hit_counter is greater than max_hits...but that's exactly what you've asked. Sorry if I'm missing something, would you mind clarifying?>=to<=returns no results in this instance, at least>=was returning results, the reason why, and the problem is the fact thatmax_hitsis encased in single quotes, i.e. interpreted as a string, as has been pointed out in the answers below :).hit_countervalues higher thanmax_hits, the first time I echoed$sizeit would return 1, the second0, which then tripsif($size == 0)and for some reason the script on a perpetual loop (keeps reloading the page).