1

I have a database of book titles.

I query the database based on a query string in a page's URL.

So for example, in the case there was a book called "Mike's Book", the query string would be 'mikes-book.' I perform some basic cleanup before passing the variable to the MYSQL query, turning 'mikes-book' into 'Mikes Book.'

The query fails, because the query string doesn't contain the apostrophe that matches the DB record.

Right now, I'm using this query:

"SELECT title FROM books WHERE title LIKE '$query_title'"

If no apostrophe is present in the DB record, the records are returned correctly. But when there is an apostrophe in the DB record, 0 results are returned.

Any ideas on what I can do here?

0

2 Answers 2

1

The problem arises because you have an lossy transformation that you're trying to reverse (the 's is apparently stripped when you create your URL). An easy way to solve this would be to keep the transformed value in the database as well, and then query for that value (mikes-book). When you update the name, also update the transformed value at the same time.

You can also reimplement the transformation function in SQL and compare each row against the transformed value, but I'd strongly suggest avoiding doing that. :-)

Sign up to request clarification or add additional context in comments.

1 Comment

That's a great idea -- I'll just add a DB column that stores the transformed value. Thanks!
0

One solution would be to use SOUNDEX but I think this is an expensive operation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.