SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query Not Working - Why?

    Hi Guys,

    I have this query i need to do:

    Code:
    SELECT ClickID, AffID, Date, Time, IP, Referrer FROM `clicks`  WHERE (`Date` >= {$MONTHLY} AND `Date` <= {$MONTHLYTO} AND `ProID` =  '3' AND `ProID` =  '6')
    But it keeps giving me errors, but if i remove the
    Code:
     AND `ProID` =  '3' AND `ProID` =  '6'
    part then it works fine but i only want it to select everything where the ProID values matches those 2 values.

    Can anyone help me here please?

    Thank you!
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If it gives you errors, then please post the errors it gives you.

    But I guess it just doesn't return any results, because proID can't be '3' AND '6' at the same time.
    Use this instead:
    Code:
    AND `ProID` IN ('3', '6')

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think you are developing in PHP and the SELECT statement is including PHP variables ({$MONTHLY}). Sometimes these are not getting assigned a value and this can result in an incomplete SQL SELECT statement:

    Code:
    WHERE (`Date` >= {$MONTHLY} AND `Date` <= {$MONTHLYTO} ...
    
    could generate
    
    WHERE (`Date` >=  AND `Date` <= 10 ...
    My suggestion is print off the SQL to see what is being sent to the database.


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
  •