a.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visitor Counter</title>
</head>
<body>
<?php
// File to store visitor count
$file = 'count.txt';
// Check if the file exists; if not, create it and initialize count
if (!file_exists($file)) {
file_put_contents($file, 0);
}
// Read current count from file
$count = (int)file_get_contents($file);
// Increment count
$count++;
// Write updated count back to file
file_put_contents($file, $count);
// Display visitor count
echo "<h1>Visitor Count</h1>";
echo "<p>The number of users visited: " . $count . "</p>";
?>
</body>
</html>
b.
<?php
// Database connection parameters
$servername = "localhost";
$username = "username"; // replace with your DB username
$password = "password"; // replace with your DB password
$dbname = "school"; // replace with your DB name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch student records from database
$sql = "SELECT id, name FROM students";
$result = $conn->query($sql);
$students = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$students[] = $row;
}
}
// Selection Sort Algorithm
for ($i = 0; $i < count($students) - 1; $i++) {
$minIndex = $i;
for ($j = $i + 1; $j < count($students); $j++) {
if ($students[$j]['name'] < $students[$minIndex]['name']) {
$minIndex = $j;
}
}
// Swap the found miminimummiminimumnimummiminimummiminimumnimumnimumnimum
element with the first element
if ($minIndex != $i) {
$temp = $students[$i];
$students[$i] = $students[$minIndex];
$students[$minIndex] = $temp;
}
}
// Display sorted student records
echo "<h1>Sorted Student Records</h1>";
foreach ($students as $student) {
echo "<p>ID: " . $student['id'] . " - Name: " .
htmlspecialchars($student['name']) . "</p>";
}
// Close connection
$conn->c