methuselah
methuselah

Reputation: 13216

Drafting SQL search entry to check if variable is is within range of values on table

I'm currently using the following SQL query for a room booking service online:

$myQuery = 'SELECT * FROM rooms WHERE Capacity >= "'.$Capacity.'" AND Location LIKE "'.$Location.'%" AND RoomType LIKE "'.$RoomType.'%"';

The problem is I'm not sure how to search for given Capacity. For example if the user inputs 20 Capacity then it should search for all the rooms with 20 capacity and over. How can I achieve this?

Upvotes: 0

Views: 80

Answers (1)

Chris
Chris

Reputation: 3121

You need to convert the VARCHAR field before performing a numeric comparison:

WHERE CONVERT(Capacity, SIGNED) >= $Capacity

Make sure not to put any quotes around $Capacity.

Upvotes: 2

Related Questions