This is an old revision of the document!
Util.php
<?php
function print_table($data, $headers) {
# print_r($data);
echo "<table class='table table-striped'>";
echo "<tr>";
foreach ($headers as $cell) {
echo "<th>$cell</th>";
}
echo "</tr>";
foreach ($data as $rows) {
echo "<tr>";
foreach ($rows as $cell) {
echo "<td>$cell</td>";
}
echo "</tr>";
}
echo "</table>";
}
<html>
<head>
<link rel="stylesheet" type="text/css"
href="bootstrap/dist/css/bootstrap.min.css">
</head>
<h2>Employees</h2>
<?php
require_once('Util.php');
$db = oci_connect('hr', 'hr', 'kurs2.wifi');
if (empty($_GET)) {
$sql = "select department_id id,
department_name
from departments where department_id in
(select department_id from employees)";
$q = oci_parse($db, $sql);
$r = oci_execute($q, OCI_DEFAULT);
$table = array();
while ($row = oci_fetch_array($q, OCI_ASSOC)) {
$table[] = $row;
}
?>
<form class="form-horizontal" role="form"
action='employees_departments.php' method='get'>
<div class="form-group">
<select class="col-sm-offset-2 col-sm-3" name='department'>
<?php foreach ($table as $dep) {
printf("<option value='%s'>%s</option>\n",
$dep['ID'], $dep['DEPARTMENT_NAME']);
}
?>
</select>
</div>
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Suchen" class="btn"/>
</div>
</form>
<?php
} else {
$department_id = $_GET['department'];
$sql = "select first_name,
last_name,
salary,
email,
hire_date
from employees where department_id = :b_department_id";
$q = oci_parse($db, $sql);
oci_bind_by_name($q, ":b_department_id", $department_id );
$r = oci_execute($q, OCI_DEFAULT);
$table = array();
while ($row = oci_fetch_array($q, OCI_NUM)) {
$table[] = $row;
}
$headers = array('First Name', 'Last Name', 'Salary',
'Email', 'Hire Date');
print_table($table, $headers);
}
?>
</html>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="bootstrap/dist/css/bootstrap.min.css">
</head>
<h2>Employees</h2>
<?php
require_once('Util.php');
$db = oci_connect('hr', 'hr', 'kurs2.wifi');
if (empty($_GET)) {
$sql = "select department_id id,
department_name
from departments where department_id in
(select department_id from employees)";
$q = oci_parse($db, $sql);
$r = oci_execute($q, OCI_DEFAULT);
$table = array();
while ($row = oci_fetch_array($q, OCI_ASSOC)) {
$table[] = $row;
}
?>
<form class="form-horizontal" role="form"
action='employees_departments.php' method='get'>
<div class="form-group">
<select class="col-sm-offset-2 col-sm-3" name='department'>
<?php foreach ($table as $dep) {
printf("<option value='%s'>%s</option>\n",
$dep['ID'], $dep['DEPARTMENT_NAME']);
}
?>
</select>
</div>
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Suchen" class="btn"/>
</div>
</form>
<?php
} else {
$department_id = $_GET['department'];
$sql = "select first_name,
last_name,
salary,
email,
hire_date
from employees where department_id = :b_department_id";
$q = oci_parse($db, $sql);
oci_bind_by_name($q, ":b_department_id", $department_id );
$r = oci_execute($q, OCI_DEFAULT);
$table = array();
while ($row = oci_fetch_array($q, OCI_NUM)) {
$table[] = $row;
}
$headers = array('First Name', 'Last Name', 'Salary',
'Email', 'Hire Date');
print_table($table, $headers);
}
?>
</html>
<