-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery4.php
More file actions
64 lines (52 loc) · 1.85 KB
/
query4.php
File metadata and controls
64 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Created by PhpStorm.
* User: kingHenry
* Date: 6/22/14
* Time: 5:52 PM
*/
@require('dbParams.php');
?>
<title>Number of Employees by Department | phpBench</title>
<?php
@include('headerAndNav.php');
?>
<div class="col-md-9 col-lg-9 col-sm-9">
<p>Write the query that displays the total count of employees per department
in descending order by department</p>
<!-- Main component for a primary marketing message or call to action -->
<table class="table table-bordered table-hover">
<thead>
<tr><th>Department Name</th>
<th>Total Employees(descending)</th>
</tr>
</thead>
<tbody>
<?php
try{
$sql="select departments.dept_name, count(dept_emp.emp_no) from departments join dept_emp on departments.dept_no=dept_emp.dept_no group by departments.dept_name order by count(dept_emp.emp_no) desc";
$dbh = new PDO("mysql:host=$hostname;dbname=$dbName",$username,$password);
foreach ($dbh->query($sql) as $row)
{
print '<tr> ';
print '<td>'.$row['dept_name'] .'</td><td>'. $row['count(dept_emp.emp_no)']. '</tr>';
}
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</tbody>
</table>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js></script>
</body>
</html>