diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2020-12-03 09:32:13 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2020-12-03 09:32:13 +0700 |
commit | 8644699f4d2fce12a41289f9627bc45be9dd1965 (patch) | |
tree | d31190ac36d10e297eeab0f6e7a70dc24395695d /usth/ICT3.2/prac/4 | |
parent | 82048ad9e3e4a96a38c8fa6a529798f40e33acb1 (diff) | |
download | cp-8644699f4d2fce12a41289f9627bc45be9dd1965.tar.gz |
[usth/ICT3.2] Develop web applications
Diffstat (limited to 'usth/ICT3.2/prac/4')
-rw-r--r-- | usth/ICT3.2/prac/4/1.php | 1 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/2.php | 2 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/3.php | 34 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/4.php | 5 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/5.php | 8 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/6.php | 5 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/7.php | 1 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/8.php | 58 | ||||
-rw-r--r-- | usth/ICT3.2/prac/4/labwork.pdf | bin | 0 -> 248067 bytes |
9 files changed, 114 insertions, 0 deletions
diff --git a/usth/ICT3.2/prac/4/1.php b/usth/ICT3.2/prac/4/1.php new file mode 100644 index 0000000..c4837a3 --- /dev/null +++ b/usth/ICT3.2/prac/4/1.php @@ -0,0 +1 @@ +<?php phpinfo(); diff --git a/usth/ICT3.2/prac/4/2.php b/usth/ICT3.2/prac/4/2.php new file mode 100644 index 0000000..a74d302 --- /dev/null +++ b/usth/ICT3.2/prac/4/2.php @@ -0,0 +1,2 @@ +<?= "'Tomorrow I\\'ll study PHP server-side scripting language.'<br>" + . "'Can you check if this command is correct : del c:\\\\*.*'"; diff --git a/usth/ICT3.2/prac/4/3.php b/usth/ICT3.2/prac/4/3.php new file mode 100644 index 0000000..7d71043 --- /dev/null +++ b/usth/ICT3.2/prac/4/3.php @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html> +<style> +table, th, td { + border: 1px solid black; + border-collapse: collapse; +} +th, td { padding: 1em } +th { font-weight: bold } +</style> + +<body> + <table> + <thead> + <tr> + <th><?= + implode("</th>\n <th>", + ['Firstname', 'Lastname', 'Age']); + ?></th> + </tr> + </thead> + <tbody> + <tr><?= + implode("\n </tr>\n <tr>", + array_map(fn($row) => "\n <td>" + . implode("</td>\n <td>", $row) + . "</td>", + [['Jill', 'Smith', 50], + ['Eve', 'Jackson', 94], + ['John', 'Doe', 80]])) + ?></tr> + </tbody> +</body> +</html> diff --git a/usth/ICT3.2/prac/4/4.php b/usth/ICT3.2/prac/4/4.php new file mode 100644 index 0000000..76bf52e --- /dev/null +++ b/usth/ICT3.2/prac/4/4.php @@ -0,0 +1,5 @@ +<?php + +function factorial(int $n): int { + return $n > 1 ? $n * factorial($n - 1) : 1; +} diff --git a/usth/ICT3.2/prac/4/5.php b/usth/ICT3.2/prac/4/5.php new file mode 100644 index 0000000..d148f5a --- /dev/null +++ b/usth/ICT3.2/prac/4/5.php @@ -0,0 +1,8 @@ +<?php + +function is_prime(int $n): bool { + for ($i = 2; $i * $i <= $n; $i++) + if ($n % $i == 0) + return false; + return true; +} diff --git a/usth/ICT3.2/prac/4/6.php b/usth/ICT3.2/prac/4/6.php new file mode 100644 index 0000000..a70cd4d --- /dev/null +++ b/usth/ICT3.2/prac/4/6.php @@ -0,0 +1,5 @@ +<?php +function sort_immutable(array $a): array { + sort($a); + return $a; +} diff --git a/usth/ICT3.2/prac/4/7.php b/usth/ICT3.2/prac/4/7.php new file mode 100644 index 0000000..daa963a --- /dev/null +++ b/usth/ICT3.2/prac/4/7.php @@ -0,0 +1 @@ +<?php // strrev is a thing diff --git a/usth/ICT3.2/prac/4/8.php b/usth/ICT3.2/prac/4/8.php new file mode 100644 index 0000000..ab84cd1 --- /dev/null +++ b/usth/ICT3.2/prac/4/8.php @@ -0,0 +1,58 @@ +<?php +try { + $conn = new PDO('mysql:host=localhost', 'wensleydale'); + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $conn->exec('DROP DATABASE IF EXISTS foo'); + $conn->exec('CREATE DATABASE foo'); + $conn->exec('USE foo'); + $conn->exec("CREATE TABLE student ( + id smallint AUTO_INCREMENT PRIMARY KEY, + name char(14), + class char(7), + mark smallint, + sex char(7))"); + + $orig = [['John Deo', 'Four', 75, 'female'], + ['Max Ruin', 'Three', 86, 'male'], + ['Arnold', 'Three', 55, 'male'], + ['Krish Star', 'Four', 60, 'female'], + ['John Mike', 'Four', 60, 'female'], + ['Alex John', 'Four', 55, 'male'], + ['My John Rob', 'Fifth', 78, 'male'], + ['Asruid', 'Five', 85, 'male'], + ['Tes Qry', 'Six', 78, 'male'], + ['Big John', 'Four', 55, 'female']]; + + $insert = $conn->prepare( + 'INSERT IGNORE INTO student (name, class, mark, sex)' + . ' VALUES (:name, :class, :mark, :sex)'); + $insert->bindParam(':name', $name); + $insert->bindParam(':class', $class); + $insert->bindParam(':mark', $mark); + $insert->bindParam(':sex', $sex); + + foreach ($orig as list($name, $class, $mark, $sex)) + $insert->execute(); + + $conn->exec("UPDATE student SET class = 'Two' WHERE mark<60"); + + $best = $conn->query("SELECT * FROM student WHERE mark>75"); + echo "Best student:<br>\n"; + while ($row = $best->fetch()) + echo $row['name'] . ' (class ' . $row['class'] + . ', mark ' . $row['mark'] . ")<br>\n"; + + echo "Good student:<br>\n"; + $good = $conn->query("SELECT * FROM student WHERE mark>60 AND mark<=75"); + while ($row = $good->fetch()) + echo $row['name'] . ' (class ' . $row['class'] + . ', mark ' . $row['mark'] . ")<br>\n"; + + echo "Average student:<br>\n"; + $avg = $conn->query("SELECT * FROM student WHERE mark<60"); + while ($row = $avg->fetch()) + echo $row['name'] . ' (class ' . $row['class'] + . ', mark ' . $row['mark'] . ")<br>\n"; +} catch(PDOException $e) { + echo "Connection failed: " . $e->getMessage(); +} diff --git a/usth/ICT3.2/prac/4/labwork.pdf b/usth/ICT3.2/prac/4/labwork.pdf new file mode 100644 index 0000000..37b267c --- /dev/null +++ b/usth/ICT3.2/prac/4/labwork.pdf Binary files differ |