barrowvian Posted May 5, 2010 Share Posted May 5, 2010 Right, I've attempted to make a simple search using fulltext and based it around the simple search that you can find in the tutorial section here on phpfreaks, this is what I have; <?php $error = array(); // creates an array for the errros to be stored. $results = array(); if (isset($_GET['searchterms'])) { $searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } if (strlen($searchTerms) > 50) { $error[] = "Search terms must be shorter than 50 characters."; } // If there are no errors, lets get the search going. if (count($error) < 1) { $sql = mysql_query("SELECT company_name, image_link FROM adverts WHERE MATCH(company_name,search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0,$_GET[results]"); if (mysql_num_rows($sql) < 1) { $error[] = "No results found for {$searchTerms}."; }else{ $results = array(); // the result array $i = 1; while ($row = mysql_fetch_array($sql)) { $results[] = "{$i}: {$row['company_name']}<br />{$row['image_link']}<br /><br />"; $i++; } } } } ?> My problem is that it is not displaying anything at all even when there is data in the table. Also, how would I go about displaying the results by relevance. I know fulltext search does this already but how do I display the actual relevance scale for the user to see? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/ Share on other sites More sharing options...
barrowvian Posted May 5, 2010 Author Share Posted May 5, 2010 also, the error messages are not showing :/ Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/#findComment-1053671 Share on other sites More sharing options...
barrowvian Posted May 5, 2010 Author Share Posted May 5, 2010 Ive messed around with it a bit and have found that I can echo the result aslong as I am not using an array.....which is probably why the errors array isnt working either. Can anyone see what the problems are with the arrays? Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/#findComment-1053693 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 try changing your array inputs to explicit and see if that helps $error[0] => 'value'; ... $error['1'] => 'value' also turn on error reporting for the page by inserting this at the top directly under the <?php opener error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/#findComment-1053702 Share on other sites More sharing options...
barrowvian Posted May 5, 2010 Author Share Posted May 5, 2010 no that didnt fix the problem, i dont understand it really cause it seems the same process as the tutorial and when i followed that it worked properly :/ Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/#findComment-1053856 Share on other sites More sharing options...
barrowvian Posted May 5, 2010 Author Share Posted May 5, 2010 nevermind. ive got the results i was after by removing the arrays and simply using echo instead! Quote Link to comment https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/#findComment-1053861 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.