SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: MySQL Search

  1. #1
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Search

    If I for example have around 600 essays in the database and somebody goes to add a new one. it will go to the verification process. i'm trying to make it so that in the admin area the admins can look for a similar one. so if the user submitted one called "How does government effect our lives" that it will search insensitively and any word 3 or more letters. i know that 3 or more is bad but i there are essays with 1 ciritical work of 3 letters. but anywayz which query would search the table for just the name (essay_name) any keyword (but 3 or more letters). i know how to do the while command and everything. i learned a LOT ever since i started asking questions here and i'm still learning. soon there's a search file that i'll be making so i'm gonna learn quite a bit now and later. thx in advance!

  2. #2
    What's HTML?
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    1,701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what you're trying to accomplish with the key word deal, but to find an essay with the same title try this SQL statement:
    SELECT essay FROM $table WHERE essay_name LIKE '%$searchterm%'
    Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
    Get your website started for less than $20! Click Here

  3. #3
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that much i know but what if there are two words. i need it to find any of them. this will only do exactly.

  4. #4
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT essay FROM table WHERE (essay_name LIKE '%$searchterm1%' OR essay_name LIKE '%$searchterm2%' OR essay_name LIKE '%$searchterm3%')

    or if you want to search for term1 AND term2, use AND instead of OR.
    Kevin

  5. #5
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any way i can put this into a array or something so the users can type in for example "something here" or "six words will go here" so it searches for any of those. because this way it's max 3 and plus i need 3 fileds.

  6. #6
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was an example, you can use as many LIKEs as you want. You could just do a thing like this though:
    Code:
    $searchterms = explode(" ",$searchwords);
    $num = count($searchterms); $i = 0;
    while ($i < $num) {
       $term .= "LIKE '%$searchterms[$i]%'";
       $i++;
       if ($i != $num) {
          $term .= " OR ";
       }
    }
    mysql_query("SELECT essay FROM table WHERE (essay_name $term)");
    Kevin


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •