Friday, January 27, 2012

How can I make a search page in PHP so that searches not entirely accurate can still return hits?

Hi, I am a PHP newbie, and I've tried this, but it doesn't work:





$result = mysql_query("SELECT * FROM book


WHERE BookID LIKE '$bookid' OR Author LIKE '$author' OR Title LIKE '$title' OR Qualification LIKE '$qual' OR (Subject LIKE '$subject' OR Subject LIKE '$other') OR Publisher LIKE '$publisher' OR ISBN LIKE '$isbn'");





This will only return the hits if the fields match exactly - so if only half of one of the fields is entered, it will not be found





Thanks|||Where you have your variables within quotes, add a % before and after them as such:


OR Author LIKE '%$author%'

No comments:

Post a Comment