ÿØÿà JFIFÿØÿà JFIF ÿØÿà JFIFÿØÿà JFIF ÿþ$
<?php
session_start();
include('config.php');
// Define current stage safely (if not already set)
$current_stage = isset($current_stage) ? intval($current_stage) : 0;
// Pagination setup
$results_per_page = 10;
// Get total number of results safely
$sql_count = "SELECT COUNT(*) AS total FROM registration";
$count_result = mysqli_query($conn, $sql_count);
$row = mysqli_fetch_assoc($count_result);
$number_of_results = intval($row['total']);
$number_of_pages = ceil($number_of_results / $results_per_page);
// Validate page number
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
if ($page < 1) $page = 1;
if ($page > $number_of_pages) $page = $number_of_pages;
// Calculate starting record
$page_first_result = ($page - 1) * $results_per_page;
// Secure query with prepared statement
$stmt = $conn->prepare("SELECT Id, Childsname, Image, stage_three_vote FROM registration ORDER BY stage_three_vote DESC LIMIT ?, ?");
$stmt->bind_param("ii", $page_first_result, $results_per_page);
$stmt->execute();
$result = $stmt->get_result();
$contestants = $result->fetch_all(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Top Contestants</title>
<style>
.btno {
background-color: #560280;
color: white;
border-radius: 10px;
}
.btno:hover {
color: #560280;
background-color: white;
font-weight: bold;
border: solid 1px #FCB900;
border-radius: 10px;
}
.card {
border-radius: 15%;
padding-bottom: 40px;
}
</style>
</head>
<body>
<?php include('nav.php'); ?>
<br>
<br>
<br>
<br>
<br>
<br>
<section class="center" style="">
<h5>Top Contestants for This Stage</h5>
<a href="search.php" style="color:#FCB900; font-weight:bold; text-align:center;">Search Contestants</a>
</section>
<main class="container">
<section>
<div class="row"><br>
<?php foreach ($contestants as $cons): ?>
<div class="col l3 m6 s12 center" style="font-family: Trebuchet MS;">
<div class="card z-depth-1 center hoverable">
<br>
<img src="<?= htmlspecialchars($cons['Image']) ?>"
alt="Contestant Photo"
class="avatar"
style="object-fit:contain; border-radius:20%; width:60%; height:250px;">
<h6 class="center" style="margin:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:#000000a4; font-weight:bold;">
<?= htmlspecialchars($cons['Childsname']) ?>
</h6>
<?php
// Determine destination page for View button
$id = intval($cons['Id']);
$viewPage = match ($current_stage) {
0 => "notyet.php?id=$id",
1 => "voter1.php?id=$id",
2 => "voter2.php?id=$id",
3 => "voter3.php?id=$id",
default => "notyet.php"
};
?>
<form action="<?= $viewPage ?>" method="POST">
<input type="hidden" name="id" value="<?= $id ?>">
<input type="submit" name="vote" class="btn btno z-depth-0" value="View">
</form>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<!-- Pagination -->
<div class="center" style="margin-top: 2rem;">
<?php if ($page > 1): ?>
<a href="?page=<?= $page - 1 ?>" class="btn z-depth-4" style="background-color:#FCB900;">Previous Page</a>
<?php endif; ?>
<?php if ($page < $number_of_pages): ?>
<a href="?page=<?= $page + 1 ?>" class="btn" style="background-color:#FCB900;">Next Page</a>
<?php else: ?>
<label style="font-size:1.2rem;">Last Page</label>
<?php endif; ?>
</div>
</main>
<br>
<?php include('footer.php'); ?>
</body>
</html>
ÿØÿà JFIF ÿþ$
ÿØÿà JFIF ÿþ$
ÿÂ