php - How to search titles that contain string in sql and push results into an array -


okay, i'm quite new mysql , can't find simple solution question. want search database , return instances of string. ex: user types "hello world" , database returns queries of "hello name world" etc. i'll take these results , push them php array.

here's attempt of according this:

include '../config.php'; $con = new pdo('mysql:host='. db_host .';dbname='. db_name .'', db_user,db_password);  $firstsearcharray = array(); // push array $searchqueryarray = explode(" ",$searchquery);//$searchquery data sent ajax $query = $con->prepare("select * srating match(title) against (':searchqueryarray')"); $query->bindparam(':$searchqueryarray',$searchqueryarray); $query->execute(); $data = $query->fetch(pdo::fetch_assoc);//i have somehow push each result array (possibly using array_push , loop) 

i believe way i'm searching isn't optimal. prefer use contains on i've heard faster, way less documented like.

this solution fulltext search.

an example:

select id,prod_name, match( prod_name ) against ( '+harpoon +article' in natural language mode) relevance testproduct  order relevance desc 

http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html

like , contains waste of time.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -