Hello,
I have a query, that I am trying to have a conditional statement for a variable that I will pass into the query. If I use one of the conditions it works, but if I try both I can't get it to work. I would appreciate any help.

Thanks,

Aaron

if (!empty($zipcode)){
$query_string = "sorted_zipmhaYY.ZIPCODE='".$zipcode."'";
}
if (!empty($MHA)){

$query_string = "mhanamesYY.MHA='".$MHA."'";

}

if($searching == "yes"){
$query = "SELECT bahwYY.$rank, sorted_zipmhaYY.ZIPCODE, mhanamesYY.MHA,bahwYY.Dependents, bahwYY.YEAR_MHA FROM bahwYY
LEFT JOIN sorted_zipmhaYY ON sorted_zipmhaYY.MHA=bahwYY.MHA
INNER JOIN mhanamesYY ON  mhanamesYY.MHA=sorted_zipmhaYY.MHA
WHERE ". $query_string ." AND bahwYY.YEAR_MHA='$year' ORDER BY sorted_zipmhaYY.zipcode ASC";

Thanks everyone I got it working

Hello,
I have a query, that I am trying to have a conditional statement for a variable that I will pass into the query. If I use one of the conditions it works, but if I try both I can't get it to work. I would appreciate any help.

Thanks,

Aaron

if (!empty($zipcode)){
$query_string = "sorted_zipmhaYY.ZIPCODE='".$zipcode."'";
}
if (!empty($MHA)){

$query_string = "mhanamesYY.MHA='".$MHA."'";

}

if($searching == "yes"){
$query = "SELECT bahwYY.$rank, sorted_zipmhaYY.ZIPCODE, mhanamesYY.MHA,bahwYY.Dependents, bahwYY.YEAR_MHA FROM bahwYY
LEFT JOIN sorted_zipmhaYY ON sorted_zipmhaYY.MHA=bahwYY.MHA
INNER JOIN mhanamesYY ON  mhanamesYY.MHA=sorted_zipmhaYY.MHA
WHERE ". $query_string ." AND bahwYY.YEAR_MHA='$year' ORDER BY sorted_zipmhaYY.zipcode ASC";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.