php - query working with like statement but not with fulltext mysql index -


am trying create search engine enable users data search. tried using in sql query , works. want use mysql fulltext index in code below not displaying data when search. table created myislam fulltext index enabled. below code

<?php include('searchajax_db.php'); if($_post) {     $q=mysql_real_escape_string($_post['search']);     $sql_res=mysql_query("select * articles match(title,body) against ('$q')          order match(title,body) against ('$q')");      //$sql_res=mysql_query("select id,title,body articles title '%$q%' or body '%$q%' ");     //     if($sql_res === false) {         die(mysql_error()); // todo: better error handling     }      while($row=mysql_fetch_array($sql_res)) {         $ut=$row['title'];         $ub=$row['body'];         $b_ust=''.$q.'';         $b_emb=''.$q.'';         $final_u = str_ireplace($q, $b_ust, $ut);         $final_e = str_ireplace($q, $b_emb, $ub); ?> <div class="show" align="left"> <?php echo '<a  data-role="button" data-transition="fade" data-icon="arrow-r" data-iconpos="right" data-inline="true" href=profile.php?id='.htmlentities($row["id"], ent_quotes, "utf-8") .' title="click find ">'.'<font color=orange></font>'.''  ?> <?php echo '<font color=greenyellow>' ?> <span class="name"><?php echo htmlentities($final_u, ent_quotes, "utf-8"); ?></span>&nbsp;<br/> <?php echo htmlentities($final_e, ent_quotes, "utf-8"); ?><br/> <?php echo '</font>' ?> </div> <?php }} ?> 

you don't need use match everywhere. condition determine rows retrieved table. right after select choose columns rows displayed. order determines column , direction rows sorted by.

this example sufficient:

select title, body articles match(title,body) against ('$q') order title asc 

i note should use prepared statements pdo or mysqli better protection using mysql_real_escape_string.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -