SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    How To Query Two Words?

    Hi,

    I have the following code which will query against one word. In this example the word is 'Host'. However I am trying to make it query against two words. The second one being 'Organiser'. I have tried a few options like OR and , but whatever I try doesn't seem to work. Any suggestions please?

    When I try Organiser on its this works but I cant work out how to query them together.

    Code:
    <?php
    $query = mysql_query("SELECT dealcompany, logo, ID, dealcountry, eventid, dealdescription, dealtitle, company, country, usertype, state
    FROM users
    JOIN deals ON deals.userid = users.id
    WHERE deals.dealtypeowner = 'Host' ORDER BY eventid DESC LIMIT 10"); 											
    																		
    while($row = mysql_fetch_array($query)) {
    	  ?>


    Code:
    <?php
    $query = mysql_query("SELECT dealcompany, logo, ID, dealcountry, eventid, dealdescription, dealtitle, company, country, usertype, state
    FROM users
    JOIN deals ON deals.userid = users.id
    WHERE deals.dealtypeowner = 'Host' OR 'Organiser' ORDER BY eventid DESC LIMIT 10"); 											
    																		
    while($row = mysql_fetch_array($query)) {
    	 
    	  ?>

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    OR links two independant conditions.
    Look at it this way and it may make more sense:
    Code MySQL:
    SELECT dealcompany, logo, ID, dealcountry, eventid, dealdescription, dealtitle, company, country, usertype, state
    FROM users
    JOIN deals 
    ON deals.userid = users.id
    WHERE deals.dealtypeowner = 'Host' 
    OR 'Organiser' 
    ORDER BY eventid 
    DESC LIMIT 1

    Note that the "OR" line doesnt make much sense. It just says "Organiser".

    Try this:
    Code MySQL:
    SELECT dealcompany, logo, ID, dealcountry, eventid, dealdescription, dealtitle, company, country, usertype, state
    FROM users
    JOIN deals 
    ON deals.userid = users.id
    WHERE deals.dealtypeowner = 'Host' 
    OR deals.dealtypeowner = 'Organiser' 
    ORDER BY eventid 
    DESC LIMIT 1
    If you start adding more options, you might want to use field IN('A','List','Of','Words') instead of field = 'A' OR field = 'B' OR......
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •