At 15:15 -0500 1/29/02, Douglas Brantz wrote: >Hello, > >I have a big problem! I need to match all patterns in schdays from a >variable schdays and if schdays = mwf it only turns up mwf and not all >entries containing M, W or F. Is there a way to do this?
Yes, but you can't do it with LIKE except in an ugly way: WHERE schdays LIKE "%M%" OR schdays LIKE "%W%" OR schdays LIKE "%F%" You're better off using regular expressions and the REGEXP operator. Regular expressions allow character classes (match any character listed inside square brackets): WHERE schdays REGEXP "[MWF]" You could also use alternation, although that's more useful when you're trying to match any of several multiple-character strings: WHERE schdays REGEXP "(M|W|F)" > >mysql> select schdays from courses where schdays LIKE "%MWF%"; >+---------+ >| schdays | >+---------+ >| MWF | >+---------+ >1 row in set (0.00 sec) > >mysql> select schdays from courses where schdays LIKE "%M%"; >+---------+ >| schdays | >+---------+ >| MWF | >| MW | >| MW | >| M | >| M | >+---------+ >5 rows in set (0.00 sec) > >I need to be able to say select schdays from courses where schdays LIKE >"%schdays%" > > >Here is my code from the program: >my $sth2 = $dbh->prepare("select >id,schdays,time_to_sec(timein),time_to_sec(time >out) from courses where schdays LIKE \"\%$cschdays\%\" AND >done=\"Yes\"....etc.. > > >So I need to be able to match any pattern with $cschdays. >Do I need to parse out the letters and pattern match each one?? It >should be easier. > >Thanks, >Douglas >[EMAIL PROTECTED] > >-- >Douglas R. Brantz >Computer Consultant >Fine & Applied Arts >Appalachian State University >Boone, NC 28608 > >828-262-6549 (office) >828-262-6312 (fax) > > > > >--------------------------------------------------------------------- >Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > >To request this thread, e-mail <[EMAIL PROTECTED]> >To unsubscribe, e-mail <[EMAIL PROTECTED]> >Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php