PrMa Posted February 2, 2008 Share Posted February 2, 2008 Ok, I have a search function on my webpage, but there are one problem that I can't overcome. The search is a BOOLEAN fulltext search, and the result is displayed as following: "text text text text text KEYWORD text text text text text" However, this only works when I'm searching for a single word, or exact phrase. So to the problem: Whenever I'm using any boolean operators, the presented result will be the first part of the searched string. Like: "Text text text text text text text text text" The keyword, in this case won't even be shown in the result. How shall i change my code so the presented result doesn't get affected by the boolean operators, and still shown as "text text text text text KEYWORD text text text text text"? Yeah, and if two or more searchwords are present, I want the first one to be displayed in the middle of the string. This is how i get and present the result: $q = mysql_query("SELECT * FROM tbl WHERE MATCH (conts) AGAINST ('$_GET[s]' IN BOOLEAN MODE)") or die(mysql_error()); while($r = mysql_fetch_array($q)){ echo "<span class=rubrik><a target=_self href=\"".$r['url']."\">",$r['title']."</a></span><br>... "; echo substr($r['conts'], stripos($r['conts'],$_GET[s])-55, 110); echo " ...<br>"; echo "<a target=_self href=\"".$r['url']."\">",$r['url']."</a><br><br>"; Hope someone have a solution to this Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/ Share on other sites More sharing options...
PrMa Posted February 2, 2008 Author Share Posted February 2, 2008 Anyone? Or can't it be done? Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456236 Share on other sites More sharing options...
The Little Guy Posted February 2, 2008 Share Posted February 2, 2008 Read my Comment, Try this: <?php //modify "title, content,URL,id" to the fields you use (check all lines) $query_count = "SELECT SQL_CALC_FOUND_ROWS title, content, URL, id FROM $searchType WHERE MATCH(URL,title,content) AGAINST ('$searchQuery' IN BOOLEAN MODE) AND content IS NOT NULL LIMIT $limitvalue, $limit"; $sql = mysql_query($query_count)or die(mysql_error()); $result_count = mysql_query("SELECT FOUND_ROWS()")or die(mysql_error()); $total = mysql_fetch_array($result_count); $totalrows = $total[0]; echo 'Found '.$totalrows.' Results'; while($r = mysql_fetch_array($q)){ echo "<span class=rubrik><a target=_self href=\"".$r['url']."\">",$r['title']."</a></span><br>... "; echo substr($r['conts'], stripos($r['conts'],$_GET[s])-55, 110); echo " ...<br>"; echo "<a target=_self href=\"".$r['url']."\">",$r['url']."</a><br><br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456255 Share on other sites More sharing options...
PrMa Posted February 2, 2008 Author Share Posted February 2, 2008 Thanks for the comment! It didn't sovle my problem tough. Or maybe I just don't understand it. However, when I execute the search using your method, I get this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10 Line 10 is: LIMIT $limitvalue, $limit"; If i take that line away, the search works exaktly the same way as before = not wanted. So, what am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456287 Share on other sites More sharing options...
p2grace Posted February 2, 2008 Share Posted February 2, 2008 That would happen if the $limitvalue is greater than the total number of rows generated by the query. Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456312 Share on other sites More sharing options...
PrMa Posted February 3, 2008 Author Share Posted February 3, 2008 Ah, but still, this doesn't do what i asked for. Someone with another solution in their backpocket? Thx Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456482 Share on other sites More sharing options...
PrMa Posted February 3, 2008 Author Share Posted February 3, 2008 Oh well, I take this as i'ts impossible? Or? Maybe you have to be a extreme php pro, and make a 5 mile long code to do it? Someone? Quote Link to comment https://forums.phpfreaks.com/topic/89054-search-result-page/#findComment-456858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.