Jump to content

<= and >= operators between string and int


Barry
 Share

Recommended Posts

I think I'm going to get an obvious duh answer here.

I have a "number of guests" text field. It's a text field because most of the time the value of this field is an int value but in some cases it's "100 guests" or "120-200"

I have the following code where $g_guests is just a GET variable.

$query = 'template="party", ';
if(isset($g_guests)){
	foreach($g_guests as $g_guest){
		switch ($g_guest) {
		    case 50:
		        $query .= 'guests=(party_guests>=1, party_guests<51), ';
		        break;
		    case 100:
		        $query .= 'guests=(party_guests>=51, party_guests<101), ';
		        break;
		    case 150:
		        $query .= 'guests=(party_guests>=101, party_guests<151), ';
		        break;
		    case 200:
		        $query .= 'guests=(party_guests>=151, party_guests<201), ';
		        break;
		    case 201:
		        $query .= 'guests=(party_guests>=201),';
		        break;
		   
		}
	}
}
$parties = $pages->find($query);

When I query between 1 and 51, I get pages back with all kinds of values een above 51.

When I query more than 201, the results I get back changes and I see a few parties with 500 guests, but also 90, 80, etc

My guess is I'm comparing apples and oranges as in, strings with ints. Is there some way to fix this without having to create a new int fields?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...