
Jason
Staff
/ Moderator

Jan 13, 2012, 8:20 AM
Post #2 of 3
(412 views)
Shortcut
|
|
Re: [rjbathgate] Where in/like
[In reply to]
|
Can't Post
|
|
Hi, This can be done using either LIKE or IN, depending on exactly how you want things to work. You would use IN if you are looking for records where a field has 1 of several values. The field you are comparing, however, needs to have only a single value (like num, for example). To get this to work, what you normally have to do is first break your multi-select value into an array, then use join() to turn it into a comma separated list. For example:
$practiceAreaList = join(",", explode("\t", trim($record['practice_areas'], "\t"))); if ($practiceAreaList) { $where = "num IN ($practiceAreaList)"; } The one catch with IN is that if practice_areas has no value, you will get a MySQL error, which is why we use the if statement. LIKE works in the exact opposite way. We use LIKE when we have a single value and are looking for it inside of a larger string (like a multi-value field). You were actually very close in your LIKE statement. What you need to do is add tab characters ("\t") to the front and end of your string. Each value in a mult-select list has a tab character in front and in back of it. Example:
'where' => "practice_areas LIKE '%\t$parent\t%'", Hope this helps --------------------------------------------------- Jason Sauchuk - Programmer interactivetools.com Hire me! Save time by getting our experts to help with your project. http://www.interactivetools.com/consulting/
|