Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to use SQLSelect with Partial match


Go to End


1474 Views

Avatar
Skullies

Community Member, 19 Posts

30 September 2016 at 2:20am

Good day
I am in need of a bit of help.
I need to do a partial match on a sqlselect
currently i have my code setup as follow

 if(isset($_POST['Keyword'])) {
				$p = $_POST['Keyword'];} else {$p=NULL;};
			$sqlQuery = new SQLSelect();
				$sqlQuery->setFrom('Products');
				$sqlQuery->selectField('ID', 'ID');
				$sqlQuery->addWhere(array('PartNumber' => $p ));
			$SearchedProducts = $sqlQuery->execute();

currently it is searching for precise matches but that is not what i am looking for
I know i can modify
 
$Price=Products::get()->filter(
		array(
		'PartNumber:PartialMatch'=>$p,
		));

but the way my code is set up it does not work with the filters

Any advice would be much appreciated
Thanks in advance
Skullies