pantinosm Posted December 1, 2006 Share Posted December 1, 2006 Hi all. I have a textbox where based of what the user types i want to find all relevant urls in my db. The problem is that it searches only for the first word e.g 'best team' it searches only for best not team. I want to search for them all, best, team, best team and vise versa.I tried to use fulltext but it doesn't work. Any suggestions?[code]$colname_rsfindwebsitesearch = "-1";if (isset($_GET['txtsearch']) && !empty($_GET['txtsearch'])) { $colname_rsfindwebsitesearch = (get_magic_quotes_gpc()) ? $_GET['txtsearch'] : addslashes($_GET['txtsearch']);}mysql_select_db($database_ibebaconn, $ibebaconn);$query_rsfindwebsitesearch = sprintf("SELECT * FROM tbllinkscyprus WHERE MATCH(URL,Title,Keywords) AGAINST ('%%%s%%') ORDER BY URL ASC", $colname_rsfindwebsitesearch);[/code] Link to comment https://forums.phpfreaks.com/topic/29125-search-using-all-keywords/ Share on other sites More sharing options...
Psycho Posted December 1, 2006 Share Posted December 1, 2006 Wow, you really like long variable names! I'm not sure if you can use multiple search "words" in a MATCH clause. I'd suggest using multiple MATCH clauses (one for each word). You can create them like this:[code]<?php$colname_rsfindwebsitesearch = "-1";if (isset($_GET['txtsearch']) && !empty($_GET['txtsearch'])) { $txtsearch = (get_magic_quotes_gpc()) ? $_GET['txtsearch'] : addslashes($_GET['txtsearch']); //Trim whitespace from the begining and end $txtsearch = trim($txtsearch); //Split into an array $txtsearchAry = explode(" ", $txtsearch); //Loop through each word to create mutiple MATCH clauses foreach ($txtsearchAry as $text) { if ($colname_rsfindwebsitesearch) { $colname_rsfindwebsitesearch .= " OR "; } $colname_rsfindwebsitesearch .= "MATCH(URL,Title,Keywords) AGAINST ('$text')" }}mysql_select_db($database_ibebaconn, $ibebaconn);$query_rsfindwebsitesearch = sprintf("SELECT * FROM tbllinkscyprus WHERE %%%s%% ORDER BY URL ASC", $colname_rsfindwebsitesearch);?>[/code] Link to comment https://forums.phpfreaks.com/topic/29125-search-using-all-keywords/#findComment-133529 Share on other sites More sharing options...
pantinosm Posted December 1, 2006 Author Share Posted December 1, 2006 It sems like a good solution but now i get this on my page.[code][b]Notice: Undefined variable: colname_rsfindwebsitesearch in c:\inetpub\wwwroot\ibeba\cyprus\cyprusearch.php on line 39[/b]$query_limit_rsfindwebsitesearch = sprintf("%s LIMIT %d, %d", $query_rsfindwebsitesearch, $startRow_rsfindwebsitesearch, $maxRows_rsfindwebsitesearch); $rsfindwebsitesearch = mysql_query($query_limit_rsfindwebsitesearch, $ibebaconn) or die(mysql_error()); $row_rsfindwebsitesearch = mysql_fetch_assoc($rsfindwebsitesearch); if (isset($_GET['totalRows_rsfindwebsitesearch'])) { $totalRows_rsfindwebsitesearch = $_GET['totalRows_rsfindwebsitesearch']; } else { $all_rsfindwebsitesearch = mysql_query($query_rsfindwebsitesearch); $totalRows_rsfindwebsitesearch = mysql_num_rows($all_rsfindwebsitesearch); } $totalPag....[/code]Please help. Link to comment https://forums.phpfreaks.com/topic/29125-search-using-all-keywords/#findComment-133630 Share on other sites More sharing options...
Psycho Posted December 1, 2006 Share Posted December 1, 2006 Looks like you may be missing a '$' when referencing that variable.I don't see the error in the code you posted, but it is difficult to read the way you have written it. When you put so much code on a line it really takes away from the benefit of getting a line number when you get an error. Link to comment https://forums.phpfreaks.com/topic/29125-search-using-all-keywords/#findComment-133682 Share on other sites More sharing options...
pantinosm Posted December 2, 2006 Author Share Posted December 2, 2006 Here is my code. The long variable names is due to macromedia dreamweaver. I cant seem to get it to wrok though. I can't find the error.[code]<?php$currentPage = $_SERVER["PHP_SELF"];$maxRows_rsfindwebsitesearch = 10;$pageNum_rsfindwebsitesearch = 0;if (isset($_GET['pageNum_rsfindwebsitesearch'])) { $pageNum_rsfindwebsitesearch = $_GET['pageNum_rsfindwebsitesearch'];}$startRow_rsfindwebsitesearch = $pageNum_rsfindwebsitesearch * $maxRows_rsfindwebsitesearch;$maxRows_rsfindwebsitesearch = 15;$pageNum_rsfindwebsitesearch = 0;if (isset($_GET['pageNum_rsfindwebsitesearch'])) { $pageNum_rsfindwebsitesearch = $_GET['pageNum_rsfindwebsitesearch'];}$startRow_rsfindwebsitesearch = $pageNum_rsfindwebsitesearch * $maxRows_rsfindwebsitesearch;if (isset($_GET['txtsearch']) && !empty($_GET['txtsearch'])) { $txtsearch = (get_magic_quotes_gpc()) ? $_GET['txtsearch'] : addslashes($_GET['txtsearch']); //Trim whitespace from the begining and end $txtsearch = trim($txtsearch); //Split into an array $txtsearchAry = explode(" ", $txtsearch); //Loop through each word to create mutiple MATCH clauses foreach ($txtsearchAry as $text) { if ($colname_rsfindwebsitesearch) { $colname_rsfindwebsitesearch = $colname_rsfindwebsitesearch . " OR "; } $colname_rsfindwebsitesearch = $colname_rsfindwebsitesearch . "MATCH(URL,Title,Keywords) AGAINST ('$text')"; } }mysql_select_db($database_ibebaconn, $ibebaconn);$query_rsfindwebsitesearch = sprintf("SELECT * FROM tbllinkscyprus WHERE %%%s%% ORDER BY URL ASC", $colname_rsfindwebsitesearch);$row_rsfindwebsitesearch = mysql_fetch_assoc($rsfindwebsitesearch);if (isset($_GET['totalRows_rsfindwebsitesearch'])) { $totalRows_rsfindwebsitesearch = $_GET['totalRows_rsfindwebsitesearch'];} else { $all_rsfindwebsitesearch = mysql_query($query_rsfindwebsitesearch); $totalRows_rsfindwebsitesearch = mysql_num_rows($all_rsfindwebsitesearch);}$totalPages_rsfindwebsitesearch = ceil($totalRows_rsfindwebsitesearch/$maxRows_rsfindwebsitesearch)-1;$currentPage = $_SERVER["PHP_SELF"];$queryString_rsfindwebsitesearch = "";if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_rsfindwebsitesearch") == false && stristr($param, "totalRows_rsfindwebsitesearch") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_rsfindwebsitesearch = "&" . htmlentities(implode("&", $newParams)); }}$queryString_rsfindwebsitesearch = sprintf("&totalRows_rsfindwebsitesearch=%d%s", $totalRows_rsfindwebsitesearch, $queryString_rsfindwebsitesearch);?>[/code] Link to comment https://forums.phpfreaks.com/topic/29125-search-using-all-keywords/#findComment-133909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.