SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member Shah Hussain's Avatar
    Join Date
    Jul 2007
    Location
    Pakistan
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Need help with a Search script

    Hello,

    I need help in php, i try my best but failed,

    so please can one help with this:

    ex:

    i have 5 videos in my database:

    1. how to make something in photoshop
    2. what is photoshop
    3. photoshop for learning
    4. creating cool effects
    5. create pixel text

    ok, when someone search this:
    how to photoshop

    then the search will show these tutorials from my database:
    1. how to make something in photoshop
    2. what is photoshop
    3. photoshop for learning.

    Please help, i am really confused!! please help
    Fstutorials.com - The best way to learn photoshop online

  2. #2
    winter is around the corner Tomer's Avatar
    Join Date
    Jul 2005
    Location
    Israel
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if this is the most effecient way to do this, but I would try splitting up each word with explode(), and then run a full-text SQL search for each word:

    PHP Code:
    SELECT FROM MyTable 
    WHERE Notes LIKE 
    "%how%"
    OR Notes LIKE "%to%"
    OR Notes LIKE "%photoshop%" 
    Let me know if you got it
    - Tom

  3. #3
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To elaborate on the above, you've got several options. The most basic is just a series of LIKE statements.

    Code PHP:
    # $terms is what they search for, i.e how to photoshop
    # Explode the keywords
    $keywords = explode(" ", $terms);
     
    # Run through each and write it as SQL
    foreach($keywords as $word) {
    	$parts[] = "name LIKE '%" . $word . "%'";
    }
     
    # Finish the SQL
    $sql = implode(" OR ", $parts);

    Where name is your field name.

    Your other option you need to set up your tables as fulltext.

    Then you can just search like this:

    Code PHP:
    $sql = "SELECT * FROM indexed WHERE MATCH(name, field2, field3) AGAINST ('" . $terms . "')";

    Where name, field2, etc are your fields which you want to look in.

  4. #4
    SitePoint Member Shah Hussain's Avatar
    Join Date
    Jul 2007
    Location
    Pakistan
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey silentcollision,

    That is what i was looking for, WOW, its works 100%, thanks alot man thanks alot..

    Thanks again silentcollision

    Sitepoint Rocks!!
    Fstutorials.com - The best way to learn photoshop online


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
  •