0

I have a mysql query that throws an error which I'm guessing is because of my judicious use of the phrase "NOT IN":

$sqlGetCountry = mysqli_query($link, "SELECT * FROM locations WHERE country='$country' AND CURTIME() > time AND '$state' NOT IN state ORDER BY time desc LIMIT 20");
$sqlNumCountry = mysqli_num_rows($sqlGetCountry);

I have a table with city, state, and country and I'm basically trying to find the queries where a given state ($state in this case, which could be Texas, Hawaii, etc.) is not in the results. I get the error:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

Anybody have a clue?

4
  • Or are you trying to find rows not matching $state? Or if $state doesn't exist in the entire table? Commented Jul 26, 2012 at 18:56
  • 1
    What is state? Is it a column? A table? Commented Jul 26, 2012 at 18:57
  • I read your question 5 times now, and I think you'd come across a lot clearer with some sample data and desired output Commented Jul 26, 2012 at 19:00
  • "I have a table with city, state, and country". state is a row in the table locations. city, state, and country are all rows in the table locations. @Michael, I'm trying to find rows not matching $state. Commented Jul 26, 2012 at 19:20

1 Answer 1

2

You can't pass a table to in, but you can pass a subquery:

SELECT  * 
FROM    locations 
WHERE   country='$country' 
        AND CURTIME() > time 
        AND '$state' NOT IN (select state from state)
ORDER BY 
       time desc 
LIMIT  20
Sign up to request clarification or add additional context in comments.

3 Comments

Oddly, I get the same results.
On rereading the question, perhaps you mena '$state' <> state? Otherwise it would help to add example in- and output, like @lc. suggests.
You are the man @Andomar. '$state' <> state works just fine. Gotta love you SQL gurus!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.