From 8644699f4d2fce12a41289f9627bc45be9dd1965 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 3 Dec 2020 09:32:13 +0700 Subject: [usth/ICT3.2] Develop web applications --- usth/ICT3.2/prac/4/1.php | 1 + usth/ICT3.2/prac/4/2.php | 2 ++ usth/ICT3.2/prac/4/3.php | 34 ++++++++++++++++++++++++ usth/ICT3.2/prac/4/4.php | 5 ++++ usth/ICT3.2/prac/4/5.php | 8 ++++++ usth/ICT3.2/prac/4/6.php | 5 ++++ usth/ICT3.2/prac/4/7.php | 1 + usth/ICT3.2/prac/4/8.php | 58 +++++++++++++++++++++++++++++++++++++++++ usth/ICT3.2/prac/4/labwork.pdf | Bin 0 -> 248067 bytes 9 files changed, 114 insertions(+) create mode 100644 usth/ICT3.2/prac/4/1.php create mode 100644 usth/ICT3.2/prac/4/2.php create mode 100644 usth/ICT3.2/prac/4/3.php create mode 100644 usth/ICT3.2/prac/4/4.php create mode 100644 usth/ICT3.2/prac/4/5.php create mode 100644 usth/ICT3.2/prac/4/6.php create mode 100644 usth/ICT3.2/prac/4/7.php create mode 100644 usth/ICT3.2/prac/4/8.php create mode 100644 usth/ICT3.2/prac/4/labwork.pdf (limited to 'usth/ICT3.2/prac/4') 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 @@ +" + . "'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 @@ + + + + + + + + + + + + + \n ", + array_map(fn($row) => "\n \n ", + [['Jill', 'Smith', 50], + ['Eve', 'Jackson', 94], + ['John', 'Doe', 80]])) + ?> + + + 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 @@ + 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 @@ +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:
\n"; + while ($row = $best->fetch()) + echo $row['name'] . ' (class ' . $row['class'] + . ', mark ' . $row['mark'] . ")
\n"; + + echo "Good student:
\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'] . ")
\n"; + + echo "Average student:
\n"; + $avg = $conn->query("SELECT * FROM student WHERE mark<60"); + while ($row = $avg->fetch()) + echo $row['name'] . ' (class ' . $row['class'] + . ', mark ' . $row['mark'] . ")
\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 Binary files /dev/null and b/usth/ICT3.2/prac/4/labwork.pdf differ -- cgit 1.4.1
\n ", + ['Firstname', 'Lastname', 'Age']); + ?>
" + . implode("", $row) + . "