Skip to content

Instantly share code, notes, and snippets.

@InspectorGadget
Last active December 10, 2018 08:48
Show Gist options
  • Save InspectorGadget/be57ecdff8dc3bdf4f764c23bb249946 to your computer and use it in GitHub Desktop.
Save InspectorGadget/be57ecdff8dc3bdf4f764c23bb249946 to your computer and use it in GitHub Desktop.
<?php
// Information at below: I've explained
// Inside Website:
<?php
error_reporting(1);
require 'includes/Handler.php';
$api = new Handler();
$rtn = $_GET['level'];
if (isset($rtn)) {
echo "<tr>";
echo "<td>" . $api->returnStudentByLevel($rtn)['id'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['fullname'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['ic'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['level'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['subject'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['branch'] . "</td>";
echo "<td>" . $api->returnStudentByLevel($rtn)['payment'] . "</td>";
echo "</tr>";
}
// Function inside includes/Handler.php
public function returnStudentByLevel($level) {
$sql = "SELECT * FROM student WHERE level = ?";
$stmt = mysqli_stmt_init($this->storedSQL);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "Prepare Failed!";
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $level);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$custArray = array("id" => $row['id'], "fullname" => $row['fullname'], "ic" => $row['ic'], "level" => $row['level'], "subject" => $row['subject'], "branch" => $row['branch'], "payment" => $this->checkPaymentStatusForCurrentMonth($row['ic']));
return $custArray;
} else {
$row = array("id" => "?", "fullname" => "No Data", "ic" => "No Data", "level" => "No Data", "subject" => "null", "branch" => "-", "payment" => "No Data");
return $row;
}
}
}
?>
// What have I done?
- I've tried to change to
`while ($row = mysqli_fetch_assoc($result)) { }`
and return the $row. Nothing really added or changed. At the time being, I have 5 records in the student table.
// What I want?
- I want to it to show all records (student) inside the Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment