PHP Select a row WHERE town=(array) and WHERE coverage=(array)

Discussion in 'PHP' started by asim_nazir1, Aug 13, 2009.

  1. #1
    Hi,

    im making a website, and im stuck on a page where the client would like to filter employees by multiple criterea,

    this works if i want to find people from leeds and london for example
    if(isset($_POST['town']))
    				{
    					$town = join("','", $town); 
    $data = mysql_query("SELECT * FROM emails WHERE town IN('$town')")
    				or die(mysql_error());
    				}
    PHP:
    But this does NOT work when i want to find people from leeds and london, and whos coverage is national
    elseif((isset($_POST['town'])) && (isset($_POST['coverage'])))
    				{
    					$town = join("','", $town); 
    				$coverage = join("','", $coverage);
    $data = mysql_query("SELECT * FROM emails WHERE coverage IN('$coverage') AND town IN ('$town')")
    				or die(mysql_error());
    					
    				}
    PHP:
    the town and coverage are chosen via form, in which the checkboxes are generated dynamically.

    Thanks for looking and any help!;)
     
    Last edited: Aug 13, 2009
    asim_nazir1, Aug 13, 2009 IP
  2. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    That should work if you change the order of the if branches I believe.

    if (isset(A)) {
    } elseif (isset(A) && isset(B)) {
    // this branch never executes
    }

    You should change to

    if (isset(A)&&isset(B)) {
    } elseif (isset(A)) {
    }
     
    stOK, Aug 13, 2009 IP
  3. asim_nazir1

    asim_nazir1 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    excellent! it works.

    i never knew it would stop when it finds a true statement.

    thankyou very much!
     
    asim_nazir1, Aug 13, 2009 IP