Code: Select all
$sql = "SELECT DISTINCT ag.AgencyID, ag.CompanyName, ag.Address, ag.StateOrProvince, ag.City, ag.PostalCode
FROM Agencies ag
INNER JOIN AgencyAreas aa ON (ag.AgencyID = aa.AgencyID)
INNER JOIN Areas ar ON (aa.AreaServedID = ar.AreaServedID)
INNER JOIN AgencyServices ags ON (ag.AgencyID = ags.AgencyID)
INNER JOIN Services s ON (ags.ServiceID = s.ServiceID)
WHERE ag.StateOrProvince ='".$province."'
AND ar.Area LIKE '".$city."'";
$zug = count($serv);
if ($zug > 0) {
$sql = $sql. " AND s.ServiceID IN (";
for ($i=0; $i < $zug; $i++){
$sql.= " '$serv[$i]' ";
}
$sql.= ' )';
}
[\PHP]
when I echo the sql string I get this:Code: Select all
SELECT DISTINCT ag.AgencyID, ag.CompanyName, ag.Address, ag.StateOrProvince, ag.City, ag.PostalCode FROM Agencies ag INNER JOIN AgencyAreas aa ON (ag.AgencyID = aa.AgencyID) INNER JOIN Areas ar ON (aa.AreaServedID = ar.AreaServedID) INNER JOIN AgencyServices ags ON (ag.AgencyID = ags.AgencyID) INNER JOIN Services s ON (ags.ServiceID = s.ServiceID) WHERE ag.StateOrProvince ='British Columbia' AND ar.Area LIKE 'vic%' AND s.ServiceID IN ( '1' '2' '3' )
[\PHP]
The problem is I've only been using mySQL and PHP for a few days now so I am not really sure if I am doing it right. Any help would be fantastic!!! Thanks a lot