Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Little problem with an AND OR logic !

    Hi,

    I am trying to ask the mysql to give my records that
    have this:
    prod_id="jkw" AND client.no=prod.no AND live="y" OR col="blue"

    Now that last OR means if the Live isn't "y" the color can be blue BUT the first two conditions must be correct

    Any idea how I need to write this in php ?

    So far I have:

    PHP Code:
    $sql "SELECT * FROM products,clients 
    WHERE products.prod_id ="
    jkw"  
    AND products.no = clients.no 
    AND live = 'y' 
    OR col='blue' 
    "

    I guess that I need some brackets somewhere ?
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Regular Coder kokjj87's Avatar
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    279
    Thanks
    1
    Thanked 55 Times in 54 Posts
    PHP Code:
    $sql "SELECT * FROM products,clients 
    WHERE products.prod_id ="
    jkw"  
    AND products.no = clients.no 
    AND (live = 'y' 
    OR col='blue') 
    "


  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Don't forget to fix the prod_id brackets too, otherwise you'll get a nice syntax error.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Hi,
    Thanks for advice.

    I have threisd to apply it to my problem (which was a bit more
    complicated that I showed in the code), but I am getting at error.

    Here is what I wrote:
    PHP Code:
    $sql "SELECT cat_cd, prod_head, prod_sum, prod_body, prod_pict, prod_link, clients.sc_name 
    FROM products,clients 
    WHERE products.prod_id = $N_prod_id 
    AND products.user_id = clients.user_id 
    AND ( (products.confirm = 'y' AND products.live = 'y') 
    OR clients.user_id = $_SESSION['expert'] )
    "

    This is the error:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/gffff/public_html/im/dgg6t.php on line 16


    Any ideas ?
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    That error means you're trying to embed a variable in a string that is too complex for a simple embedding; you need to enclose the variable in squiggly brackets {}.

    In your case the $_SESSION['expert'] needs such treatment.

    See http://us2.php.net/manual/en/language.types.string.php for lots of useful information on all of PHP's string powers. (find the Variable Parsing section for this particular issue)

  • #6
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Fumigator can you please go easy on the technical jargon. some people around here are just new to coding and may be intimidated by such jargon as below

    Code:
    squiggly brackets


    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •