hello again,
so can anybody explain how to search the title or body on every lower or uppercase.
because if i add a lowercase letter into the search box he can't find it
when i add a uppercase in the search box then he find it.
is there anyway to do that?
[syntax=php]
$keywords = preg_split('#\s+#', mysql_real_escape_string($term));
$title_where = "`post_title` LIKE '%" . implode("%' OR `post_title` LIKE '%", $keywords) . "%'";
$body_where = "`post_body` LIKE '%" . implode("%' OR `post_body` LIKE '%", $keywords) . "%'";
[/syntax]
thank you.
search a Tutorial by jacek
Re: search a Tutorial by jacek
Hi there
Somebody smarter than me please correct me if I'm wrong, but BLOB is case sensitive (if that's what your using)
Depending on whats there, you may want to convert input to lower case with the MySQL 'lower' function.
An example:
[syntax=sql]SELECT names FROM test LIKE LOWER('%John%')[/syntax]
And you may want to use more variables, to look neater:
[syntax=php]$something = implode("%' OR `post_title` LIKE '%", $keywords);
$title_where = "`post_title` LIKE '%{$something}%'";[/syntax]That's generally how I do it
Source: http://forums.cpanel.net/f5/mysql-upper-lowercase-search-problem-49465.html
Somebody smarter than me please correct me if I'm wrong, but BLOB is case sensitive (if that's what your using)
Depending on whats there, you may want to convert input to lower case with the MySQL 'lower' function.
An example:
[syntax=sql]SELECT names FROM test LIKE LOWER('%John%')[/syntax]
And you may want to use more variables, to look neater:
[syntax=php]$something = implode("%' OR `post_title` LIKE '%", $keywords);
$title_where = "`post_title` LIKE '%{$something}%'";[/syntax]That's generally how I do it
Source: http://forums.cpanel.net/f5/mysql-upper-lowercase-search-problem-49465.html
Re: search a Tutorial by jacek
hello again,
hmm can you make the example with the code i gived.
because its makes me a little confused
hmm can you make the example with the code i gived.
because its makes me a little confused
Re: search a Tutorial by jacek
i3c wrote:hello again,
hmm can you make the example with the code i gived.
because its makes me a little confused
Sure!
Just know that I have not tested this...
[syntax=php]$keywords = preg_split('#\s+#', mysql_real_escape_string($term));
$implode_title = implode("%' OR `post_title` LIKE '%", $keywords);
$implode_body = implode("%' OR `post_body` LIKE '%", $keywords);
$title_where = "`post_title` LIKE LOWER('%{$implode_title}%')";
$body_where = "`post_body` LIKE LOWER('%{$implode_body}%')";[/syntax]
Re: search a Tutorial by jacek
thanks for the fast answer.
okay works but seems it only search on the first word off the title
so it don't search anymore on the complete string
okay works but seems it only search on the first word off the title
so it don't search anymore on the complete string
Re: search a Tutorial by jacek
Could you please get a post or something and export it for me?
(take out any personal data )
So I can test this myself. It could be the RegEx your using.
(take out any personal data )
So I can test this myself. It could be the RegEx your using.
Re: search a Tutorial by jacek
Okay, I noticed that entering one word into the search in upper or lower case will not matter.
However, when you enter 2 words, it will say that no results were found. (and it won't search the body)
I noticed that the search terms are glued together with "+" instead of standard spaces. This could only bring me to
your regex: "#\s+#"
This is where I get off. I have no knowledge of RegEx (or search in general).
Your probably better off waiting for somebody else to pick up this thread :3
Sorry :<
However, when you enter 2 words, it will say that no results were found. (and it won't search the body)
I noticed that the search terms are glued together with "+" instead of standard spaces. This could only bring me to
your regex: "#\s+#"
This is where I get off. I have no knowledge of RegEx (or search in general).
Your probably better off waiting for somebody else to pick up this thread :3
Sorry :<
Re: search a Tutorial by jacek
its okay don't need to say sorry
im glad you wanted to help
thanks so far.
im glad you wanted to help
thanks so far.
Re: search a Tutorial by jacek
You could always take a different approach ?
There is a nice little tutorial here: http://www.codeforest.net/simple-search-with-php-jquery-and-mysql
There is a nice little tutorial here: http://www.codeforest.net/simple-search-with-php-jquery-and-mysql
Re: search a Tutorial by jacek
You could convert the keywords and the stuff in the table both to lowercase before checking.
[syntax=php]$keywords = preg_split('#\s+#', mysql_real_escape_string(strtolower($term)));
$title_where = "LOWER(`post_title`) LIKE '%" . implode("%' OR LOWER(`post_title`) LIKE '%", $keywords) . "%'";
$body_where = "LOWER(`post_body`) LIKE '%" . implode("%' OR LOWER(`post_body`) LIKE '%", $keywords) . "%'";[/syntax]
note that all those LOWER() calls will not be great for performance so it would be worth looking in to fulltext search.
[syntax=php]$keywords = preg_split('#\s+#', mysql_real_escape_string(strtolower($term)));
$title_where = "LOWER(`post_title`) LIKE '%" . implode("%' OR LOWER(`post_title`) LIKE '%", $keywords) . "%'";
$body_where = "LOWER(`post_body`) LIKE '%" . implode("%' OR LOWER(`post_body`) LIKE '%", $keywords) . "%'";[/syntax]
note that all those LOWER() calls will not be great for performance so it would be worth looking in to fulltext search.