Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.