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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need a push in the right direction

    I have a multi checkbox with 9 boxes they can select any three from the 9

    This is one box of the 9
    <input type="checkbox" name="subject[]" value="organic" onClick="CountChecks(this)">for Organic</font>

    then submit to
    <?php
    $where = join($subjectChecked, ' = "y" OR ') . ' = "y"';

    //Create Query
    $query = "SELECT * FROM part WHERE $where AND WARDS = 'y' AND pet = 'y'";
    $result = mysql_query($query) or die (mysql_error());
    $num = mysql_numrows($result);
    ?>


    If in the database pet='n' it still brings it up as 'y'

    it seem to find WARDS and 'y' and then ignore pet

    any ideas on this please

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Try this modification:

    PHP Code:
    $where '('.join($subjectChecked' = "y" OR ') . ' = "y")'
    That may fix your problem.

  • Users who have thanked mlse for this post:

    Piperjim (01-27-2008)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'm with MLSE, thinking that is the problem. Its an error with the logic flow - I believe that SQL runs logic from left to right instead of with the magnitude of the operator.
    So, with SQL
    1 OR 2 OR 3 AND 4 AND 5 is interpreted as:
    (1 OR 2 OR (3 AND 4) AND 5) If i"m not mistaken.
    This is different from PHP where the operators have a magnitude (and why you can choose between AND or && for example)
    1 || 2 || 3 AND 4 && 5
    Would be interpreted as:
    (1 OR 2 OR 3) AND (4 AND 5)
    For example. I can't find the logic flow on the php site (someone else confirm please), but if I'm not mistaken '||' operator has a higher precedence than the 'AND' operator, resulting in its evaluation first.
    Hope thats the problem your are having, and hope that gives you a little insight as to what the problem is caused by.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Piperjim (01-27-2008)

  • #4
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks mlse
    Great
    That piece of code seem to have done the trick

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank to you Fou-Lu
    I think your logic is correct I will look into this a bit more when I have more time
    But a Thank you for this thought


  •  

    Posting Permissions

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