Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:44:20+00:00 2026-05-27T13:44:20+00:00

I created a Fulltext search in Boolean Mode using PHP/MySQL. It runs perfectly, with

  • 0

I created a Fulltext search in Boolean Mode using PHP/MySQL. It runs perfectly, with relevance ranking and index assigned to concerned database fields. The database contains two tables:

business -> name, description, contact, address, serialid

*search_terms* -> terms, querytime, date_searched, results.

Then now, I want to get all the search results and assigned it to a variable ($results). This $result will be stored to the search_term table along with terms, querytime and date_searched.

Here is my code (without $result)

function search($term){
    $term = mysql_real_escape_string($term);
    $startTime = microtime(true);
    $query = mysql_query("SELECT *, MATCH (Name) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel1, MATCH (Description) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel2, MATCH (Keywords) AGAINST ('+$term*' IN BOOLEAN MODE) AS rel3 FROM business WHERE MATCH (Name,Description,Keywords) AGAINST ('+$term*' IN BOOLEAN MODE) ORDER BY (rel1*0.60)+(rel2*0.25)+(rel3*0.15) DESC") or die(mysql_error());
    $endTime = microtime(true);
    $queryTime = substr($endTime - $startTime, 0,6);
    if(mysql_num_rows($query) == 0){
        echo "<p>No results found for <i>". $term ."</i></p>";
    }
    else{
        while($row = mysql_fetch_assoc($query)){
            echo "<h4><a href='viewBusiness.php?serial=" . $row['SerialId'] . "'>" . $row['Name'] . "</a></h4>";
            $desc = substr($row['Description'], 0,100);
            $score = $row['rel1'] + $row['rel2'] + $row['rel3'];
            echo "<p>" . $desc .". . .</p>";
        }
        $numOfResult = mysql_num_rows($query);
        echo "<hr/><p><b>" . $numOfResult ." </b>result(s) found within " . $queryTime . " seconds.</p>";
        $ip = $_SERVER['REMOTE_ADDR'];
        $query2 = mysql_query("INSERT INTO search_term(Term, QueryTime, Ip) VALUES('$term', '$queryTime', '$ip')") or die(mysql_error());
    }
}

I am novice in PHP and this is my first application. Thank you very much for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:44:20+00:00Added an answer on May 27, 2026 at 1:44 pm

    You can create and save your $result to DB like this:

    /* Your code before the cycle... */
    
    $result = array(); /* The array where to store results */
    while($row = mysql_fetch_assoc($query)) {
        /* Your code for printing, just as posted... */
        $result[] = $row; /* Store the result row in the array */
    }
    
    /* The rest of your code, before second query... */
    
    /* Serialize the result data and save it to database */
    $result_serialized = mysql_real_escape_string(serialize($result));
    $query2 = mysql_query("
        INSERT INTO search_term(Term, QueryTime, Ip, result) 
        VALUES('$term', '$queryTime', '$ip', '$result_serialized')
    ") or die(mysql_error());
    

    But be careful: $result (and so $result_serialized) can be very very big depending on results type and number. Be sure you can handle it. The result field in the search_term DB table must be a TEXT or a bigger string data type column.

    And read about serialize() and unserialize()!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a fulltext search on two columns which I created
How to force MySQL to create FULLTEXT index of words with 1, 2, and
We have a simple search on our site that uses MySQL fulltext search and
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I am studying fulltext search engines for django. It must be simple to install,
I've created a search before, and it works fine, but trying to do it
I have the following TVF for fulltext search: FUNCTION [dbo].[Fishes_FullTextSearch] (@searchtext nvarchar(4000), @limitcount int)
I have to hack a content management system to support fulltext search for a
In my project we use Lucene 2.4.1 for fulltext search. This is a J2EE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.