On 3/8/06, Adrian Bruce <[EMAIL PROTECTED]> wrote: > one solution (may not be the best but would work) would be to use 'like' > instead of '=' and then put wildcards %%$var % around the variable so > that if it is not there then it wount effect the query. >
Yeah, I use this kind of "trick" for SELECTs based on user submited forms. So your query would be: SELECT * FROM $table_name WHERE sname LIKE '$search_string%' AND area LIKE '%$area%' AND interest LIKE '%$interest%' ORDER BY fname $type; > Ade > > [EMAIL PROTECTED] wrote: > > >I am fairly new to sql and am now getting into the area of slightly more > >complex queries. > > > >At present my query is > > > > $query = "SELECT * FROM $table_name WHERE sname LIKE '$search_string%' > >ORDER BY fname $type"; > > > >but I have two other filters which may or may not be chosen. (area, and > >interest). > > > > $query = "SELECT * FROM $table_name WHERE sname LIKE '$search_string%' AND > >area='area' AND interest='interest' ORDER BY fname $type"; > > > >but what if nether is chosen, or only one? Is there an AND/OR operator or > >similar in mysql? > > > > > >Thanks, > > > >Ross > > > > > > > > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] > > -- Daniel da Veiga Computer Operator - RS - Brazil -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V- PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++ ------END GEEK CODE BLOCK------ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]