defroster Posted August 18, 2010 Share Posted August 18, 2010 Hello, I would like to build a php search engine against a mysql database. I am looking for a tutorial but haven't been able to find any good ones. Any ideas of where I can find one? I need one where I can search with several words and if it has the stemmer.class.inc and so on would be great also. thanks, df Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/ Share on other sites More sharing options...
MadTechie Posted August 18, 2010 Share Posted August 18, 2010 This is basically a MySql fulltext query, your still need to apply the stemmer but other than that is one sql query! Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1100932 Share on other sites More sharing options...
defroster Posted August 18, 2010 Author Share Posted August 18, 2010 Thanks, do you know of any tutorial that implements this that would show me all the steps? Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1100933 Share on other sites More sharing options...
defroster Posted August 19, 2010 Author Share Posted August 19, 2010 Hello, I tried this $search=$_GET['search']; $query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (title,titletext) AGAINST ('db' WITH QUERY EXPANSION)"; but get this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198 any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101377 Share on other sites More sharing options...
Timber232 Posted August 19, 2010 Share Posted August 19, 2010 Ok, so you want a search query ehh? I'd recomend using LIKE. for example: // $_POST is from a form "<input type="text" name="search_text"></input>" but I'm sure you know this already $postSearch = $_POST[search_text]; $search = mysql_query("SELECT * FROM <table here> WHERE <row here> LIKE '$postSearch%' "); //displaying the search result while ($row = mysql_fetch_array($search) { echo $row[<insert row here>] . '<br />'; echo $row[<insert row here>] . '<br />'; echo $row[<insert row here>] . '<br />'; } First time replying to anything in any forum, I hope I made it clear enough. if not , I'll paste a piece of my code for my search query here as an example. if ($searchBy == "sDay") { $search = mysql_query("SELECT * FROM syn_test WHERE Date LIKE '$postSearch%'"); while($row = mysql_fetch_array($search)) { echo "<tr><td>" . $row['synID'] . "</td>" . "<td>" . $row['Username'] . "</td>" . "<td>" . $row['Password'] . "</td>" . "<td>" . $row['Date'] . "</td>". "<td>" . $row['Time'] . "</td>". "</tr>"; } } Hope that helps! P.S ignore the if statement "if ($searchBY == "sDay")" that may confuse you. Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101420 Share on other sites More sharing options...
MadTechie Posted August 20, 2010 Share Posted August 20, 2010 Do a mysql_error and post the error Hello, I tried this $search=$_GET['search']; $query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (title,titletext) AGAINST ('db' WITH QUERY EXPANSION)"; but get this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198 any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101555 Share on other sites More sharing options...
defroster Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks when I do echo mysql_error(); I get the response: 'Query was empty' Hmm... Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101565 Share on other sites More sharing options...
DirtySnipe Posted August 20, 2010 Share Posted August 20, 2010 Why don't you just take a look at this php / mysql search engine script. Look into the code to figure out how they did it and make your own from there. http://www.sphider.eu/ Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101574 Share on other sites More sharing options...
MadTechie Posted August 20, 2010 Share Posted August 20, 2010 Thanks when I do echo mysql_error(); I get the response: 'Query was empty' Hmm... Humm maybe it would be better to post all the code that around the problem Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101582 Share on other sites More sharing options...
defroster Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks, this is what the code looks like: /* PAGINATION FOR *SEARCH */ $search=$_GET['search']; $query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION)"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "index.php"; //your file name (the name of this file) $limit = 2; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ //SQL FOR *SEARCH $query="SELECT * FROM videos, categories.cat WHERE $search MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION) ORDER BY (videos.up-videos.down) DESC LIMIT $start, $limit"; $result = mysql_query($sql); echo mysql_error(); And it gives me the following error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198 Query was empty Where line 198 is the following: $total_pages = mysql_fetch_array(mysql_query($query)); Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101599 Share on other sites More sharing options...
pagegen Posted August 20, 2010 Share Posted August 20, 2010 //SQL FOR *SEARCH ....... $result = mysql_query($sql); change the above to $result = mysql_query($query); should work the problem is u dont have a varuable $sql any where in the script u provided and the query u have for search has been assigned to a varuable $query Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101640 Share on other sites More sharing options...
defroster Posted August 20, 2010 Author Share Posted August 20, 2010 Thanks. Now I get this error? 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 'MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION)ORDER' at line 1 I am using Server version: 5.1.44 Any ideas what can be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/211105-building-a-search-engine/#findComment-1101646 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.