Listeleme Sayfası
<?php
session_start();
// Oturum kontrolü
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('Location: admin.php');
exit;
}
// Veritabanı bağlantısı
$servername = "localhost";
$username = "xxxx";
$password = "xxx";
$dbname = "xxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Veritabanına bağlanırken hata oluştu: " . $conn->connect_error);
}
// Sayfalama işlemi için gerekli parametreler
$page = isset($_GET['page']) ? $_GET['page'] : 1; // Aktif sayfa numarası
$limit = 50; // Her sayfada görüntülenecek kayıt sayısı
// Toplam kayıt sayısını al
$countQuery = "SELECT COUNT(*) AS total FROM ogrenciler";
$countResult = $conn->query($countQuery);
$totalRecords = $countResult->fetch_assoc()['total'];
// Toplam sayfa sayısını hesapla
$totalPages = ceil($totalRecords / $limit);
// Geçerli sayfa numarasını sınırla
$page = max($page, 1);
$page = min($page, $totalPages);
// Kayıtları sorgula
$offset = ($page - 1) * $limit;
$sql = "SELECT * FROM ogrenciler LIMIT $offset, $limit";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Ogrenci Listesi</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
.pagination {
margin-top: 20px;
}
.pagination a {
display: inline-block;
padding: 8px 16px;
text-decoration: none;
border: 1px solid #ddd;
color: #555;
}
.pagination a.active {
background-color: #4CAF50;
color: white;
border: 1px solid #4CAF50;
}
.pagination a:hover:not(.active) {
background-color: #ddd;
}
</style>
</head>
<body>
<h2>Ogrenci Listesi</h2>
<table>
<tr>
<th>ID</th>
<th>Ad</th>
<th>Soyad</th>
<th>Sınıf</th>
<th>Veli Adı</th>
<th>Veli Telefon</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['ad'] . "</td>";
echo "<td>" . $row['soyad'] . "</td>";
echo "<td>" . $row['sinif'] . "</td>";
echo "<td>" . $row['veli_ad'] . "</td>";
echo "<td>" . $row['veli_telefon'] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='6'>Kayıt bulunamadı</td></tr>";
}
?>
</table>
<!-- Sayfalama bağlantıları -->
<div class="pagination">
<?php
if ($totalPages > 1) {
for ($i = 1; $i <= $totalPages; $i++) {
$active = ($i == $page) ? "active" : "";
echo "<a href=\"welcome.php?page=$i\" class=\"$active\">$i</a>";
}
}
?>
</div>
<a href="download.php" target="_blank">Tüm Kayıtları İndir</a>
</body>
</html>
<?php
// Veritabanı bağlantısını kapatma
$conn->close();Excel İndirme Sayfası<?php
// Veritabanı bağlantısı
$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Veritabanına bağlanırken hata oluştu: " . $conn->connect_error);
}
// Sorgu: Tüm kayıtları seç
$sql = "SELECT * FROM ogrenciler";
$result = $conn->query($sql);
// Excel dosyasını oluşturma
require_once 'PHPExcel/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
// Başlık satırını ekle
$sheet->setCellValue('A1', 'ID');
$sheet->setCellValue('B1', 'Ad');
$sheet->setCellValue('C1', 'Soyad');
$sheet->setCellValue('D1', 'Sınıf');
$sheet->setCellValue('E1', 'Veli Adı');
$sheet->setCellValue('F1', 'Veli Telefon');
// Kayıtları döngüyle ekle
$rowIndex = 2;
while ($row = $result->fetch_assoc()) {
$sheet->setCellValue('A' . $rowIndex, $row['id']);
$sheet->setCellValue('B' . $rowIndex, $row['ad']);
$sheet->setCellValue('C' . $rowIndex, $row['soyad']);
$sheet->setCellValue('D' . $rowIndex, $row['sinif']);
$sheet->setCellValue('E' . $rowIndex, $row['veli_ad']);
$sheet->setCellValue('F' . $rowIndex, $row['veli_telefon']);
$rowIndex++;
}
// Dosya adını belirleme ve kaydetme
$filename = 'student_records.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean(); // Clear output buffer (important for download)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
exit;
?>githubtan PHPExcel dosyasını indirip dosya dizinine attım.
excel indirme bağlantısına tıkladığımda "bu sayfa çalışmıyor"hatası alıyorum.