Basic search script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Basic search script

Post by josh »

I have a database of books and I was wondering how to implement a basic search script, I guess what I am asking is how do I see the % of similarity between term 1 and term 2, would there be a better way... perhaps does term1==term2 but if they are searching star wars I would want star wars 1 2 3 4 5 6 and 7 etc... you get what I mean?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

You can do a simple replace:

Code: Select all

<?php
$squeryreplaced=str_replace(" ","%') or (story like '%",$squerylow);     //if the user give 2 search terms ???

$query=mysql_query("select * from news where (story like '%$squeryreplaced%')");
?>
Change "news" with the name of your table
You can change "story" with books or whatever you want to search for
$squerylow is the value that holds the terms the user used :wink:
Post Reply