SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the broken code:

    1. $query = "SELECT * FROM entertainment"
    2. . " WHERE ent_category = '$class'"
    3. . " and start >= DATE_SUB('$Today', INTERVAL 15 DAY)"
    4. . " and end >= '$Today'"
    5. . " or duration == 'on_going'"
    6. . " or duration == 'single_date'"
    7. . " ORDER BY ent_category asc";

    Here are the parts that work well togeather:

    1. $query = "SELECT * FROM entertainment"
    2. . " WHERE ent_category = '$class'"
    3. . " and start >= DATE_SUB('$Today', INTERVAL 15 DAY)"
    4. . " and end >= '$Today'"
    7. . " ORDER BY ent_category asc";

    Here is the goal: To pull all the data regardless of the status of one day show, multiple day show or on going listing.


    This is code for an entertainment posting element of my page. I want to have three durations (some will be ongoing listings, some one day and some with a start and stop date).

    Here is the problem:
    I need to use the OR in the SELECT but am not sure just how to do it. Clarifying: If i do an OR is that for the immediately preceding AND or for all the preceeding ANDs?

    Suggestions?

    thanks

  2. #2
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off, you don't need to worry about breaking it over multiple lines -- PHP and MySQL do not care and it's easier to read (in my opinion) like this:
    Code:
    $query = "SELECT * 
                FROM entertainment
               WHERE ent_category = '$class'
                 AND start >= DATE_SUB( '$Today', INTERVAL 15 DAY)
                 AND end >= '$Today' 
                  OR duration == 'on_going' 
                  OR duration == 'single_date'
            ORDER BY ent_category asc";
    Anyways, you can use parenthesis ( ) to set order of operations – you’d have to tweak it but basically group the operations like this:

    Code:
    $query = "SELECT * 
                FROM entertainment
               WHERE ent_category = '$class'
               AND ( start >= DATE_SUB( '$Today', INTERVAL 15 DAY)
               AND   end >= '$Today' )
                OR ( duration == 'on_going' 
                OR   duration == 'single_date' )
            ORDER BY ent_category asc";

  3. #3
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks MattR

    $query = "SELECT *
    FROM entertainment
    WHERE ent_category = '$class'
    AND start >= DATE_SUB( '$Today', INTERVAL 15 DAY)
    AND ( end >= '$Today'
    OR duration == 'on_going'
    OR duration == 'single_date' )
    ORDER BY ent_category asc";

    I have set up the (). I have some other problem also but I will work that,

    Thank You for the help.

    peace

    Hi, I found the other proble, The query failed caused by the == .

    Thanks

    ed==
    Last edited by edshuck; Feb 25, 2001 at 15:30.

  4. #4
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem, yeah single = in SQL.

    HOLY COW. What are these neat things above the post window?


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
  •