SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up making an internal search

    i need to make an internal search for my website.

    I need to be able to search through maybe 5-10 Mysql tables. the thing i was looking into was the LIKE function in mysql...

    but, i dont really know how to use that...

    any help would be appreciated, or a good script others use.

  2. #2
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easy way is:

    Code:
    SELECT * FROM table_name WHERE some_column LIKE '%some%text%'
    % is a wildcard in SQL (like the * in php), there are other ways of searching like this, you should do a search on that using google.

    Hope this helps :0

  3. #3
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you need to search text in 5-10 tables you need a db redesign.. With the pages/articles stored in the same table. Then, you can use full text search too for better search.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by praetor View Post
    If you need to search text in 5-10 tables you need a db redesign.. With the pages/articles stored in the same table. Then, you can use full text search too for better search.
    Quote Originally Posted by fastbuilder View Post
    i need to make an internal search for my website.

    I need to be able to search through maybe 5-10 Mysql tables. the thing i was looking into was the LIKE function in mysql...

    but, i dont really know how to use that...

    any help would be appreciated, or a good script others use.
    The LIKE operator could not be the solution for search. But Full Text search is the best way of searching your whole database. Study about it in the MySQL manual. And i also think that as praetor said you should change the database table structure too since it will be very though to search in all 5 tables.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up making an internal search

    i need to make an internal search for my website.

    I need to be able to search through maybe 5-10 Mysql tables. the thing i was looking into was the LIKE function in mysql...

    but, i dont really know how to use that...

    any help would be appreciated, or a good script others use.

  6. #6
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can't search "maybe 5 - 10 MySQL tables", you have to specify the tables and the columns (attributes) in your search query.

    Select attributes
    from tablename
    where attribute7 like 'fred%';

    finds any occurrance in column attribute7 in tablename that starts with fred


    Select attributes
    from tablename
    where attribute7 like '%fred%';

    finds any occurence in the column attribute7 in tablename that has fred anywhere in it


    Select attributes
    from tablename
    where attribute7 like '%fred';

    finds any instance in column attribute7 in tablename that ends in fred

    And if you want to search another table you then need a second query

    Select otherAttributes
    from otherTablename
    where attribute2 like '%fred%';

    and so on

    you can NOT say the equivalent of "is fred anywhere in any of my tables"

  7. #7
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Brisbane, Australia
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr John View Post
    You can't search "maybe 5 - 10 MySQL tables", you have to specify the tables and the columns (attributes) in your search query.

    Select attributes
    from tablename
    where attribute7 like 'fred%';

    finds any occurrance in column attribute7 in tablename that starts with fred


    Select attributes
    from tablename
    where attribute7 like '%fred%';

    finds any occurence in the column attribute7 in tablename that has fred anywhere in it


    Select attributes
    from tablename
    where attribute7 like '%fred';

    finds any instance in column attribute7 in tablename that ends in fred

    And if you want to search another table you then need a second query

    Select otherAttributes
    from otherTablename
    where attribute2 like '%fred%';

    and so on

    you can NOT say the equivalent of "is fred anywhere in any of my tables"
    Not necessarily true. You can search more than one table at once. You just need to specify what you want from each table...

    Code:
    SELECT a.fieldOne, a.fieldTwo, b.fieldOne
    FROM TableOne as a, TableTwo as b
    WHERE a.fieldOne LIKE "%one%"
    OR b.fieldOne LIKE "%one%"
    AND a.fieldTwo LIKE "%two%";

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    fastbuilder, please do not post the same thread again a fourth time

    one thread per topic!

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up making an internal search

    i need to make an internal search for my website.

    I need to be able to search through maybe 5-10 Mysql tables. the thing i was looking into was the LIKE function in mysql...

    but, i dont really know how to use that...

    any help would be appreciated, or a good script others use.

  10. #10
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for LIKE see the following link

    LIKE
    Barbara

  11. #11
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey fastbuilder,

    Did you read your last post with the same topic? http://www.sitepoint.com/forums/showthread.php?t=483102

    It has been said, please do not post same topic twice or more. I think if you might be in ignore list here. Lol

    Don't worry i am not the authorized person here to say so but just the request from my side if you have already posted the same topic, why do you need to post again it? You can just bump up in the same post.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  12. #12
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up making an internal search

    i need to make an internal search for my website.

    I need to be able to search through maybe 5-10 Mysql tables. the thing i was looking into was the LIKE function in mysql...

    but, i dont really know how to use that...

    any help would be appreciated, or a good script others use.

  13. #13
    SitePoint Addict
    Join Date
    Jan 2007
    Location
    Romania
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at string comparison functions. It's a good start.

  14. #14
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    more duplicate threads merged

    fastbuilder has been banned until he/she gets the message
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •