I'm learning PHP, and can't seem to figure out if loops can be run inside a function.
My code works when not inside a function, but I cannot to get it to output when I wrap it in a function.
I'm trying to input an agency name ($jur) and get a list of names associated with that name from a data base.
function jur($conn, $jur){
// SQL that runs the search in the data base for all employees associated with an agency
$EmployeeListSQL = "SELECT emp.NAME as NAME, jur.NAME as AGENCY FROM SMARTCM . dbo . EMPMAST as emp
inner join SMARTCM . dbo . EMP_TO_JURIS as empjur
on emp.UniqueKey = empjur.FK_EMP_KEY
inner join SMARTCM . dbo . JURISDICT as jur
on empjur.FK_JURIS_KEY = jur.UniqueKey
where jur.name = '$jur'";
$employeeListSET = sqlsrv_query($conn, $EmployeeListSQL);
// create an array with all the names fetched from the data base
while($employee = sqlsrv_fetch_array( $employeeListSET, SQLSRV_FETCH_ASSOC)){
$employeeListArray[] = $employee['NAME'];
}
// list all the array items
foreach($employeeListArray as $employee){
echo $employee . "<BR>";
}
}
// Try to call the function list
jur($conn, 'Girard');