At 03:15 PM 1/29/2002 -0500, 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? > >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.
I'd do this by doing a pattern match on %M% and then joining it with a pattern match on %W% and then joining it with a pattern match on %F%. I forget which type of join you want, it's the one that is logical-OR. You may wish this was easier (and there may be an easier way of doing it), but the fundamental problem is that you think pattern matching in SQL works differently to how it actually works. --------------------------------------------------------------------- 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