clay1 Posted September 2, 2009 Share Posted September 2, 2009 I have a form which produces an postgresql query. It selects all the records where the event city = the posted variable As such: $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; This works fine-- however sometimes I need to select more than just the posted variable. For example if the post is washington dc, I also want the query to select alexandria I tried: if ($_POST['select'] == 'washington dc'){ $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' OR 'alexandria' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; But I get an invalid syntax error. How can I do this? Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 2, 2009 Share Posted September 2, 2009 Its just like PHP in that each condiftion must stand on it's own. You can't do where x = 1 or 2, you have to do where x = 1 or x = 2. I don't use postgresql, but this should be right if ($_POST['select'] == 'washington dc'){ $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' OR \"event city\" ~* 'alexandria' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; Quote Link to comment Share on other sites More sharing options...
clay1 Posted September 2, 2009 Author Share Posted September 2, 2009 Thanks! That worked the only thing I needed to change was it needs the date for both $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}' OR \"event city\" ~* 'alexandria' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; Thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.