Adam Posted September 17, 2008 Share Posted September 17, 2008 Hi guys. I was just wondering if there's some kind of operator or something that can mean the field can equal any value? Basically I select records based on the 'site', but there's an option for all. So without having to go.. if ($site = 'all') //run this query else //run this query I could either have it return records from site 1, site 2, etc. or have it return records with any value for site.. Hope that makes sense?? Cheeers, Adam... Quote Link to comment https://forums.phpfreaks.com/topic/124630-solved-field-any-value/ Share on other sites More sharing options...
rajivgonsalves Posted September 17, 2008 Share Posted September 17, 2008 Can you provide some code what your using ? Quote Link to comment https://forums.phpfreaks.com/topic/124630-solved-field-any-value/#findComment-643672 Share on other sites More sharing options...
Adam Posted September 17, 2008 Author Share Posted September 17, 2008 Sure.. $resSQL = mysql_query("SELECT * FROM reservations WHERE (datefrom BETWEEN '{$year}/{$month}/01' AND '{$year}/{$month}/{$daysInMonth}') AND site = '{$site}' ORDER BY datefrom ASC") or die(mysql_error()); That's the query I'm using. Most of it doesn't really matter right now except "AND site = '{$site}' " .. I have a drop down menu that allows them to select site 1, site 2, site 3, etc. the sites are stored in the database by IDs .. so the value of $site would equal 1, or 2, or 3, etc. except there's an option for ALL, so I was wondering if there was some special operator or something I could enter in the $site variable in order to - in english - return records with 'site' field equalling anything. Any clearer?? Thanks! Adam Quote Link to comment https://forums.phpfreaks.com/topic/124630-solved-field-any-value/#findComment-643677 Share on other sites More sharing options...
Adam Posted September 17, 2008 Author Share Posted September 17, 2008 I've come up with a soloution using PHP, but I'd still like to know if there is such a thing in MySQL? would make the code a little nearer, and may help me on another project... $resSQL = "SELECT * FROM reservations WHERE (datefrom BETWEEN '{$year}/{$month}/01' AND '{$year}/{$month}/{$daysInMonth}')"; /* If ALL sites selected do not specify site in query */ if ($site != 'ALL') $resSQL .= "AND site = '{$site}'"; Cheers, Adam... Quote Link to comment https://forums.phpfreaks.com/topic/124630-solved-field-any-value/#findComment-643683 Share on other sites More sharing options...
scottybwoy Posted September 17, 2008 Share Posted September 17, 2008 That is the answer you have come up with. Well done. Quote Link to comment https://forums.phpfreaks.com/topic/124630-solved-field-any-value/#findComment-643702 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.