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

  • Home
  • SEARCH
  • 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 6902503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:48:22+00:00 2026-05-27T07:48:22+00:00

i have a variable and an user_name i want to search on a string(function_description)

  • 0

i have a variable and an user_name i want to search on a string(function_description) of the user_name for it

whats wrong with this :

$function_keywords = mysql_real_escape_string($_POST['function_keywords']);
if($function_keywords=="" || empty($function_keywords)){
    redirect("show.php?functions=PHP");
}
//trim whitespace from the stored variable
$trimmed = trim($function_keywords);
//separate key-phrases into keywords
$trimmed_keywords = explode(" ",$trimmed);
// Build SQL Query for each keyword entered
foreach ($trimmed_keywords as $trimm){
// MySQL "MATCH" is used for full-text searching.
//this code is ebv weird , should check out soon!
$query = "SELECT * 
          FROM functions
          WHERE isEnabled=1 AND isPrivate=0
          AND function_description LIKE '{$trimm}' 
          AND user_name='{$user_name}'   
          ";
 // Execute the query to  get number of rows that contain search kewords
 $results=mysql_query ($query,$connection);
  • 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-27T07:48:23+00:00Added an answer on May 27, 2026 at 7:48 am

    That’s highly inefficient. If someone puts in 5 keywords, you’d be running the search 5 times and getting 5 sets of results. Try something more along these lines:

    $words = $_POST['function_keywords'];
    if ($words == '') {
        ... abort ...
    }
    
    $parts = trim(explode(' ', $words));
    $clauses = array();
    foreach($parts as $part) {
        $clauses[] = "function_description LIKE '%" . mysql_real_escape_string($part) . "%'";
    }
    
    $clause = implode(' OR ' , $clauses);
    
    $sql = "SELECT .... WHERE (isEnabled=1) AND (isPrivate=1) AND (user_name='$user_name') AND ($clause)";
    $result = mysql_query($sql) or die(mysql_error());
    

    This’ll build up a long series of or statements for each keyword specified, and run the whole thing as a single query.

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

Sidebar

Related Questions

I have this: one string variable which holds the class name ( $classname )
I have a string user setting and want to select a particular variable with
I have variable @count of datatype int.I am setting values to this @count. I
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have the variable string (user gets to set it via a ListView with
I have a MySQL fulltext search engine and I want to allow the user
If I have user id variable, what is correct java naming convention for it?
I have an ASP.NET web form which I am adding a variable number User
I have some user-submitted variables that I want to display in a different part
How I can have variable number of parameters in my function in C++. Analog

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.