Table.Php
<?php
require_once('util.php');
class MyDB extends SQLite3 {
function __construct() {
$this->open('db/applicant.sqlite');
}
}
$db = new MyDB();
if (!$db) {
echo $db->lastErrorMsg();
}
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 0;
switch($sort) {
case 0:
$sql = 'SELECT * FROM "students" LIMIT 100';
break;
case 1:
$sql = 'SELECT * FROM "students" ORDER BY "profession" LIMIT 100';
break;
case 2:
$sql = 'SELECT * FROM "students" WHERE "achievements" = 1 LIMIT 100';
break;
case 3:
$sql = 'SELECT * FROM "students" WHERE "achievements" = 3 OR "achievements" = 4 LIMIT 100';
break;
default:
$sql = 'SELECT * FROM "students" LIMIT 100';
}
$results = $db->query($sql);
function checkSort ($id) {
if ($id == 0) {
return true;
} else if (isset($_GET['sort'])) {
if ($_GET['sort'] == $id) {
return true;
} else {
return false;
}
} else {
return false;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Таблица абитуриентов</title>
<link rel="stylesheet" type="text/css" href="common.css" />
<script type="text/javascript" src="common.js"></script>
</head>
<body>
<div class="tableHeader">
<a href="/applicant">← Анкета</a>
<h1>Таблица абитуриентов</h1>
<div class="sortHeader">
<div class="textField">
<select onchange="window.location = '?table&sort=' + this.selectedIndex" id="selectSort">
<option value="0" <?php if (checkSort(0)) { ?>selected<?php } ?>>Не выбрана</option>
<option value="1" <?php if (checkSort(1)) { ?>selected<?php } ?>>Специальности в алфавитном</option>
<option value="2" <?php if (checkSort(2)) { ?>selected<?php } ?>>Наличие золотой медали</option>
<option value="3" <?php if (checkSort(3)) { ?> selected<?php } ?>>Олимпиадники</option>
</select>
<span class="hightlightBorder"></span>
<label for="profession">Сортировка</label>
</div>
</div>
</div>
<table id="table">
<tbody>
<tr>
<th id="rowID">ID</th>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
<th>Моб. номер</th>
<th>Специальность</th>
<th>День рождения</th>
<th>Страна</th>
<th>Город</th>
<th>Улица</th>
<th>Номер дома</th>
<th>Страна (уч.)</th>
<th>Город (уч.)</th>
<th>Название (уч.)</th>
<th>Номер (уч.)</th>
<th>Дата окончания (уч.)</th>
<th>Достижения</th>
<th>Номер аттестта</th>
<th>Дата получения</th>
</tr>
<?php
while ($row = $results->fetchArray()) {
echo '<tr>';
echo '<td id="rowID" alt="'. $row['ID'] .'">'. $row['ID'] .'</td>';
echo '<td>'. $row['Surname'] .'</td>';
echo '<td>'. $row['Name'] .'</td>';
echo '<td>'. $row['SecondName'] .'</td>';
echo '<td>'. $row['Phone'] .'</td>';
echo '<td>'. $row['profession'] .'</td>';
echo '<td>'. $row['Birthday'] .'</td>';
echo '<td>'. $countries[$row['Country']] .'</td>';
echo '<td>'. $cities[$countries[$row['Country']]][$row['City']] .'</td>';
echo '<td>'. $row['Street'] .'</td>';
echo '<td>'. $row['StreetNumber'] .'</td>';
echo '<td>'. $countries[$row['SchoolCountry']] .'</td>';
echo '<td>'. $cities[$countries[$row['SchoolCountry']]][$row['SchoolCity']] .'</td>';
echo '<td>'. $row['SchoolName'] .'</td>';
echo '<td>'. $row['SchoolNumber'] .'</td>';
echo '<td>'. $row['SchoolDate'] .'</td>';
echo '<td>'. $achieve[$row['achievements']] .'</td>';
echo '<td>'. $row['docNumber'] .'</td>';
echo '<td>'. $row['docDate'] .'</td>';
echo '</tr>';
}
$db->close();
?>
</tbody>
</table>
</body>
</html>