User's Manual

Combining Departments and Employees
5-12 Oracle Database Express Edition 2 Day Plus PHP Developer Guide Beta Draft
substr(first_name,1,1) || '. '|| last_name as employee_name,
hire_date,
to_char(salary, '9999G999D99') as salary,
nvl(commission_pct,0) as commission_pct
FROM employees
WHERE department_id = :did
ORDER BY employee_id asc";
$deptid = $_SESSION['deptid'];
2. Edit anyco.php. In construct_employees(), update the call to
db_do_query() to pass the bind information:
$conn = oci_connect();
$bindargs = array();
array_push($bindargs, array('DID', $deptid, -1));
$emp = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW, $bindargs);
3. Edit anyco.php. In construct_departments() save the department identifier in a
session parameter:
$_SESSION['currentdept'] = $current;
$_SESSION['deptid'] = $deptid;
This saves the current department identifier from the Department page as a
session parameter, which is used in the Employees page.
4. Edit anyco.php. Create a function get_dept_name() to query the department
name for printing in the Department and Employee page titles:
function get_dept_name($conn, $deptid)
{
$query =
'SELECT department_name
FROM departments
WHERE department_id = :did';
$conn = db_connect();
$bindargs = array();
array_push($bindargs, array('DID', $deptid, -1));
$dn = db_do_query($conn, $query,OCI_FETCHSTATEMENT_BY_COLUMN, $bindargs);
return($dn['DEPARTMENT_NAME'][0]);
}
5. Edit anyco.php. Modify construct_employees() to print the department
name in the page heading:
$deptname = get_dept_name($conn, $deptid);
ui_print_header('Employees: '.$deptname);
6. Edit anyco.php. Modify construct_departments() to print the department
name in the page heading:
$deptname = get_dept_name($conn, $deptid);
ui_print_header('Department: '.$deptname);
7. Edit anyco.php. Modify construct_insert_emp() so the default department
is obtained from the session parameter passed in the $emp array to
ui_print_insert_employee():