Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem with LIKE query

Featured Replies

I've created a database search function an have encountered a problem I don't know how to fix.

The problem is that the database content contains html formatted word breaks in long words.

 

The database entries are in Danish (a language where we don't split connected words).

Example: The english word(s) "Multimedia project" would be just one word in danish ("Multimedieprojekt") so in the database the word is stored as "multimedie­projekt". The ­ allows the word to be divided at line breaks with CSS hyphens.

 

As a result the word "Multimedieprojekt" will not show up in search results because the word technically doesn't exist in the db.

 

So the question is:

Is there any way I can filter out $shy; wordbreaks in my db-query or do I have to load all db entries and filter the results in PHP?

 

Here's the important part of the search function

//input from the search form
$sanitized = filter_var($_GET['search'], FILTER_SANITIZE_STRING);

//The returnConString function creates a new PDO instance 
$con = returnConString();

//Store matches between the input and the content in an array declared earlier(CONTENTTABLE is just a constant representing the table)
$queryPost=$con->prepare('SELECT post_id, post_title, content FROM '.CONTENTTABLE.' WHERE content LIKE :keywords');

//binding the input as a param in the querystring
$queryPost->bindValue(':keywords', '%' . $sanitized . '%');

Edited by Nillervision

  • Author

I think there are two or three options here:

 

1) Bring out all of the data and then use PHP to filter it. I don't think this is very efficient though.

2) Add an extra column in the database that has the same data in it but without the '­'s and search on that.

3) See if you can use CAST to 'copy' the column without the '­'s. I'm not sure if this is possible. But Google might drag up some useful info.

Thanks NOCK. I'm beginning to think option two with a keyword index it might be the best idea. It will also be more efficient as i can remove a lot of insignificant words.

I don't think option 3 will work. I thought CAST was only used to return data as a specific datatype. Can it also be used to return altered content?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.