Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Searching the Exact Phrase in Mysql

Codes here !

Moderators: macek, egami, gesf

Searching the Exact Phrase in Mysql

Postby amwangi4 » Mon Apr 15, 2013 9:57 pm

Hi Geeks, I was working on a search engine which works on exact phrase searching. I have already created the MVC architecture. The following is the query to search in the model.


function searchlaws($reg)
{
$sql = "select A.actnumber,S.sectionintrotext, S.sectionnumber,S.subsectionnumber,S.subsectionbody
from Act as A join section as S on (a.actnumber = s.actnumber)
WHERE match (a.actnumber) against (". $reg ."IN BOOLEAN MODE) OR
match (a.acttitle) against (". $reg."IN BOOLEAN MODE) ";





$query = $this->db->query($sql);
return $query->result();
}
amwangi4
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Apr 15, 2013 9:31 pm
Location: Nairobi

Re: Searching the Exact Phrase in Mysql

Postby egami » Tue Apr 16, 2013 1:27 pm

by default, SQL already searches via exact phrase.


Ie.


$a = "This helps me a lot"

$query = "SELECT * FROM myTable WHERE value='$a'"

Will look for anything that contains "This helps me a lot" (Depending on your table setup, this may or may not be case sensitive so be wise).
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.