Searching the Exact Phrase in Mysql

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 15, 2013 9:31 pm
Location: Nairobi

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();

User avatar
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Searching the Exact Phrase in Mysql

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

by default, SQL already searches via exact phrase.


$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).

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Baidu [Spider] and 3 guests