From a36dca379132fceb1ca65daccf95cc9deeb16bf1 Mon Sep 17 00:00:00 2001 From: sandeephc24 Date: Wed, 4 Dec 2024 12:41:06 +0530 Subject: [PATCH] Create San.html --- San.html | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 San.html diff --git a/San.html b/San.html new file mode 100644 index 0000000..dce431d --- /dev/null +++ b/San.html @@ -0,0 +1,182 @@ + + + + + + + + + + +Student Record Sorter + + + + + + +
+ +

Student Records

+setAttribute(PDO::ATTR_ERRMODE, + +PDO::ERRMODE_EXCEPTION); + +// Fetch student records + +$stmt = $pdo->query("SELECT * FROM students"); + +$students = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// Selection sort function + +function selectionSort(&$arr, $n) { + +for ($i = 0; $i < $n - 1; $i++) { +$min_idx = $i; + +for ($j = $i + 1; $j < $n; $j++) { + +if ($arr[$j]['gpa'] < $arr[$min_idx]['gpa']) { + +$min_idx = $j; + +} + +} + +if ($min_idx != $i) { + +$temp = $arr[$i]; + +$arr[$i] = $arr[$min_idx]; + +$arr[$min_idx] = $temp; + +} + +} + +} + +// Sort students by GPA + +selectionSort($students, count($students)); + +// Display sorted student records + +echo ""; +echo ""; + +foreach ($students as $student) { + +echo ""; + +echo ""; + +echo ""; + +echo ""; + +echo ""; + +} + +echo "
IDNameGPA
" . htmlspecialchars($student['id']) . "" . htmlspecialchars($student['name']) . "" . htmlspecialchars($student['gpa']) . "
"; + +} catch(PDOException $e) { + +echo "Connection failed: " . $e->getMessage(); + +} + +?> + +
+ + + +