jakebur01 Posted October 10, 2007 Share Posted October 10, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/ Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 try using the MATCH function in SQL look it up Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365970 Share on other sites More sharing options...
jakebur01 Posted October 10, 2007 Author Share Posted October 10, 2007 I found some stuff on preg_match, is this what I need. I need a little boost on how to empliment something like that into the current code that I have. Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365971 Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 no in your SQL statement use MATCH like WHERE MATCH (variable,variable2) AGAINST ("$keyword") Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365974 Share on other sites More sharing options...
jakebur01 Posted October 10, 2007 Author Share Posted October 10, 2007 Like this? $sql = "SELECT No, description, title, author, isbn, price FROM books WHERE MATCH No, description, title, author, isbn, price AGAINST '$mysearch'"; Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365976 Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 looks good Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365977 Share on other sites More sharing options...
jakebur01 Posted October 10, 2007 Author Share Posted October 10, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365978 Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 <?php $sql = "SELECT No, description, title, author, isbn, price FROM books WHERE MATCH (No, description ,title, author, isbn, price) AGAINST ('%$mysearch%')";?> Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365979 Share on other sites More sharing options...
jakebur01 Posted October 10, 2007 Author Share Posted October 10, 2007 Still no dice. I don't know what's going on, i've been playing with it. I don't want to drive you crazy with this thing man. Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365982 Share on other sites More sharing options...
darkfreaks Posted October 10, 2007 Share Posted October 10, 2007 should look up MYSQL MATCH function it tells ya how to go about doing a search that way http://devzone.zend.com/node/view/id/1304 Quote Link to comment https://forums.phpfreaks.com/topic/72573-solved-critiquing-search/#findComment-365984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.