0

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";
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by AMADH
0

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";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.