SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot darksystem's Avatar
    Join Date
    Jan 2005
    Location
    Fayettville, North Carolina
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simplify query AND and OR logic (was "Help please")

    Hello,

    I wonder if there's a better code of this

    Code:
    "SELECT btd.directory_id, d.id, d.name, d.contactname, d.active, d.link, d.description  
    FROM business_to_directorytypeid btd, directory d  
    WHERE (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.name like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.contactname like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.address like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.city like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.state like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.zip like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.phone like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.email like '$keyword%') or (d.id=btd.directory_id and btd.directorytype_id='$mod_categories' and 
    d.description like '%$keyword%') ORDER by d.name ASC";
    Any help will be much appreciated

    regards
    Ebay API, OSC/CRE/OscMax/ZenCart/SEO Services
    Lucki Multimedia - Email

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,276
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT btd.directory_id
         , d.id
         , d.name
         , d.contactname
         , d.active
         , d.link
         , d.description  
      FROM business_to_directorytypeid btd
    INNER
      JOIN directory d  
        ON d.id = btd.directory_id 
     WHERE btd.directorytype_id = '$mod_categories' 
       AND (
           d.name        like '$keyword%'
        OR d.contactname like '$keyword%'
        OR d.address     like '$keyword%'
        OR d.city        like '$keyword%'
        OR d.state       like '$keyword%'
        OR d.zip         like '$keyword%'
        OR d.phone       like '$keyword%'
        OR d.email       like '$keyword%'
        OR d.description like '%$keyword%'
           )
    ORDER 
        by d.name ASC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot darksystem's Avatar
    Join Date
    Jan 2005
    Location
    Fayettville, North Carolina
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your the man, it works. I tried that before but it didn't work maybe I missed something that's why I switched to the long method. cheers mate. thanks a lot. I really appreciate it.
    Ebay API, OSC/CRE/OscMax/ZenCart/SEO Services
    Lucki Multimedia - Email


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
  •