PDA

View Full Version : search using LIKE in mysql


Tien
3-25-05, 01:39 AM
I try to use the LIKE in my query for searching but it will not match with some other characters in the database therefore, search cannot be found.

Here is the problem:

the information in the database contain apostrophe but instead of regular apostrophe it is this character in my information '

for example: "My friend's name" will be like this in my database "My friend's name"

Now when I do the search using php script it will return nothing because it doesn't match with what in the database. The search is showing "My friend's name" but in the database is "My friend's name". So there is no match!

But that is not the only problem that I have. Now in my database I also have information using regular apostrophe but not '

So now how can I do a query so that it will match both apostrophe and ' ?


$find = @$_GET["find"];
$find = trim(strtolower($find));
query("SELECT tid,title,views,description FROM $tb1 WHERE forum_id='$forumid' AND LOWER(description) LIKE '$find%' ORDER BY `description`,`title`,`tid` ASC ","1");

kakao
3-25-05, 07:20 AM
I didn't test it:
$find = @$_GET["find"];
$find = trim(strtolower($find));
query("SELECT tid,title,views,description FROM $tb1 WHERE forum_id='$forumid' AND LOWER(htmlspecialchars_decode(description, ENT_QUOTES)) LIKE '$find%' ORDER BY `description`,`title`,`tid` ASC ","1");
http://www.php.net/manual/en/function.htmlspecialchars-decode.php

B&T
3-25-05, 11:35 AM
I don't think you need to do that strtolower and the lower in the sql. I believe that LIKE is case insensitive.

As for searching with both strings . . . not sure how to do that easily. I would probably fix the database.