WTL_Assignment_9[2][1]
WTL_Assignment_9[2][1]
Assignment No.9
Aim:
Create the database table with the entries mentioned:
[rollNo, studName, studDept, passingYear, classGrades] Grades should be either {First
Class, Second Class, Pass}
Design the UI as given below and show the appropriate result through PHP script
Theory:
PHP stands for Hypertext Preprocessor. PHP is a very popular and widely-used open source
server-side scripting language to write dynamically generated web pages. PHP was originally
created by Rasmus Lerdorf in 1994. It was initially known as Personal Home Page.
PHP scripts are executed on the server and the result is sent to the web browser as plain
HTML.
PHP can be integrated with the number of popular databases, including MySQL,
PostgreSQL,
Oracle, Microsoft SQL Server, Sybase, and so on
The values assigned to a PHP variable may be of different data types including simple string
and numeric types to more complex data types like arrays and objects.
PHP supports a total eight primitive data types: Integer, Floating point number or Float,
String, Booleans, Array, Object, resource and NULL. These data types are used to construct
variables. Now let's discuss each one of them in detail.
Arrays are complex variables that allow us to store more than one value or a group of values
under a single variable name.
Types of Arrays in PHP
There are three types of arrays that you can create. These are:
Indexed array/ Numeric array — An array with a numeric key.
Associative array — An array where each key has its own specific value.
Multidimensional array — An array containing one or more arrays within itself.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Records</title>
</head>
<body>
<br><br>
<br>
<?php
if (isset($_POST['display'])) {
$conn = new mysqli("localhost", "username", "password", "database_name");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$year = $_POST['year'];
$classGrade = $_POST['classGrade'];
if ($classGrade == "All") {
$sql = "SELECT * FROM students WHERE passingYear = ?";
} else {
$sql = "SELECT * FROM students WHERE passingYear = ? AND classGrades = ?";
}
$stmt = $conn->prepare($sql);
if ($classGrade == "All") {
$stmt->bind_param("i", $year);
} else {
$stmt->bind_param("is", $year, $classGrade);
}
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<table border='1'>";
echo "<tr><th>Roll
No</th><th>Name</th><th>Department</th><th>Year</th><th>Class</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["rollNo"] . "</td><td>" . $row["studName"] . "</td><td>"
. $row["studDept"] . "</td><td>" . $row["passingYear"] . "</td><td>" . $row["classGrades"]
. "</td></tr>";
}
echo "</table>";
} else {
echo "No results found.";
}
$stmt->close();
$conn->close();
}
?>
</body>
</html>
Output:
Conclusion: