+ Reply to Thread
Results 1 to 2 of 2

Thread: string search in mysql

  1. #1
    rafiq009 is offline x10Hosting Member rafiq009 is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    16

    Lightbulb string search in mysql

    hi, i am trying to play with string. so i need some suggestion.

    for example i have a database containing id, book name, author name, publish year. now i would like to make a php script that will search book information from the database. User may type part of the book name or author name, may be uppercase or lowercase problem or spell mistake then how could i provide a good search result?

    Database:
    store(id, book_title, author, publish_year)

    form:
    HTML Code:
    <form method="post" action="result.php">
    <table >
    	<tr>
    		<td ><strong>Book Name</strong></td>
    		<td ><strong>Author</strong></td>
    	</tr>
    	<tr>
    		<td><input name=book_name type=text ></td>
    		<td><input name=author type=text ></td>
    	</tr>
    	<tr>
    		<td colspan=2 align=center><input type=submit name=Search value=Search></td>
    	</tr>
    <table>
    </form>
    result.php :

    PHP Code:
    <?php
    $title
    =$_POST['book_name'];
    $author $_POST["author"];

    $sql=mysql_query("select * from store where book_title like %$title% or author like %$author% ");
    $db=mysql_query($sql);
    ?>

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: string search in mysql

    This is not an easy task. You could try fulltext searching, though it won't fulfill all your requirements (it's case insensitive, but won't handle spelling mistakes). As per Nathan Ostgard's suggestion, to handle spelling differences you can create additional columns holding the soundex string for each column. You could also examine and incorporate code that gives spelling suggestions when there are no search results (e.g. Robert Douglass' Drupal spelling suggestion patch (yeah open source!)). Your best bet is probably to search the web for a search engine, rather than trying to write your own. Just be warned that anything other than a trivial search engine will require a high usage of server resources. If you have a free site, it could repeatedly get suspended for resource usage.

    Also see the thread "Improved Search Algorythm (Alternative to FULLTEXT)".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. MySQL connection string /.NET
    By intune in forum Programming Help
    Replies: 2
    Last Post: 03-20-2010, 04:40 AM
  2. MySQL connection string
    By smartdb in forum Free Hosting
    Replies: 1
    Last Post: 02-15-2010, 03:56 AM
  3. Can one search the contents of files for a string?
    By Sunflower-Products in forum Free Hosting
    Replies: 2
    Last Post: 07-28-2009, 11:16 PM
  4. search mysql
    By acellec in forum Programming Help
    Replies: 2
    Last Post: 05-27-2009, 02:27 AM
  5. MySql Connection String
    By fenris in forum Programming Help
    Replies: 10
    Last Post: 01-10-2009, 12:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers