Jump to content

Recommended Posts

Please help me to better this search. It is searching columns in my database. If $mysearch is a phrase of three or four words the search does not work well at all. Only one word searches will pull data.

 

Is their some way to bust up $mysearch to where it will search a phrase. Ex. "Universal Gas Cap"

function get_search_books($mysearch)
{
   // query database for the books in a category
  $mysearch =$_POST['searchlike'];
  $mysearch= trim($mysearch);
   if (!$mysearch || $mysearch=='')
     return false;
   
   $conn = db_connect();
  $sql = "SELECT No, description, title, author, isbn, price FROM books ";
$sql .= "WHERE `No` LIKE '%$mysearch%' ";
$sql .= "OR `description` LIKE '%$mysearch%' ";
$sql .= "OR `title` LIKE '%$mysearch%' ";
$sql .= "OR `author` LIKE '%$mysearch%' ";
$sql .= "OR `isbn` LIKE '%$mysearch%' ";

   $result = @$conn->query($sql);
   if (!$result)
     return false;
   $num_books = @$result->num_rows;
   if ($num_books ==0)
      return false;
   $result = db_result_to_array($result);
   return $result;
}

Link to comment
https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/
Share on other sites

It's not pulling anything now. What am I doing wrong?

 

function get_search_books($mysearch)
{
   // query database for the books in a category
  $mysearch =$_POST['searchlike'];
  $mysearch= trim($mysearch);
   if (!$mysearch || $mysearch=='')
     return false;
   
   $conn = db_connect();
   
    $sql = "SELECT No, description, title, author, isbn, price FROM books WHERE MATCH No, description, title, author, isbn, price AGAINST '$mysearch'";
/* $sql = "SELECT No, description, title, author, isbn, price FROM books ";
$sql .= "WHERE `No` LIKE '%$mysearch%' ";
$sql .= "OR `description` LIKE '%$mysearch%' ";
$sql .= "OR `title` LIKE '%$mysearch%' ";
$sql .= "OR `author` LIKE '%$mysearch%' ";
$sql .= "OR `isbn` LIKE '%$mysearch%' "; */

   $result = @$conn->query($sql);
   if (!$result)
     return false;
   $num_books = @$result->num_rows;
   if ($num_books ==0)
      return false;
   $result = db_result_to_array($result);
   return $result;
}

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.