Jump to content

[SOLVED] Critiquing Search


jakebur01

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;
}

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.