Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 ANDing multiple values in a field
ln_e Offline
Junior Member
**
Posts: 3
Joined: Sep 2015
Post: #5
RE: ANDing multiple values in a field
Thanks for the help anyway! :)

I think I've figured it out in the meantime, although would still like to know if there is a less hacky solution.

For anyone looking to do something similar, this is the part that handles multiple select queries in xt_forumdhooks.php

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if(!xthreads_empty($threadfield_cache[$field]['multival'])) {
				// ugly, but no other way to really do this...
				$qstr = '(';
				$qor = '';
				switch($filtermode) {
					case XTHREADS_FILTER_PREFIX:
						$cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname));
						$qlpre = "%\n";
						$qlpost = '';
						break;
					case XTHREADS_FILTER_ANYWHERE:
						$cfield = $fieldname;
						$qlpre = $qlpost = '';
						break;
					default:
						$cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname, "\"\n\""));
						$qlpre = "%\n";
						$qlpost = "\n%";
				}
				foreach($val2 as &$v) {
					$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
					if(!$qor) $qor = ' OR ';
				}
				$qstr .= ')';
			}



Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' OR ';

This is where the multiple values are ORed together, you can just duct tape it with an AND:

Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' AND ';


Not a pretty solution by any means, but it does the job.
09-24-2015 03:12 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
ANDing multiple values in a field - ln_e - 09-23-2015, 11:45 PM
RE: ANDing multiple values in a field - ln_e - 09-24-2015 03:12 AM

 Standard Tools
Forum Jump: