Jump to content

problem with simple search


barrowvian

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/200808-problem-with-simple-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.