Reputation: 31
User gives the input and input could be a full or partial name. The query should display all the matching output. This is the code that I am using
c.execute("SELECT name FROM ALLNAMES WHERE Cname ='" + ('%'+ Input.get()+'%') + "';")
I am using python and the output is an empty list which doesn't look right.
Upvotes: 0
Views: 185
Reputation: 1059
You meant to have like query, not equality. So in this case it will be:
c.execute("SELECT name FROM ALLNAMES WHERE Cname LIKE '"+ ('%'+ Input.get()+'%') + "';")
https://www.mysqltutorial.org/mysql-like/
Beware of that is not good idea to put query parameters in query string. It is vulnerable for easy sql injection. Use at least query params.
Upvotes: 0
Reputation: 10873
You need like
instead of =
c.execute("SELECT name FROM ALLNAMES WHERE Cname LIKE '" + ('%'+ Input.get()+'%') + "';")
Upvotes: 1