انا عملت زر تحميل داخل جدول لكن دالة لاتعمل
<?php
// الاتصال بقاعدة البيانات
include 'database.php';
include 'navbar.php';
// استعلام لاسترجاع البيانات
$id = $_GET['id'];
$sql = "SELECT * FROM `student` WHERE id=".$id;
$result = $conn->query($sql);
// إضافة البيانات إلى التقرير
$html = '<h1> درجات الطالب</h1>';
$html .= '<table border="1" cellpadding="5">';
$html .= '<tr><th>عنوان العمود1</th><th>عنوان العمود2</th><th>عنوان العمود3</th></tr>';
while ($row = $result->fetch_assoc()) {
$html .= '<tr>';
$html .= '<td>' . $row['fname'] . '</td>';
$html .= '<td>' . $row['course_name'] . '</td>';
$html .= '<td>' . $row['course_code'] . '</td>';
$html .= '</tr>';
}
$html .= '</table>';
$html .= '<div style="text-align:center;">تاريخ الطباعة: ' . date('Y-m-d H:i:s') . '</div>';
وعملت دالة لكن لايعمل
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>الرئيسية</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container">
<table class="table my-5 table-bordered table-striped">
<thead>
<tr>
<th class="text-center table-primary" scope="col">#</th>
<th class="text-center table-primary" scope="col"> رقم القيد</th>
<th class="text-center table-primary" scope="col">اسم الطالب</th>
<th class="text-center table-primary" scope="col"> اسم المقرر</th>
<th class="text-center table-primary" scope="col">رمز المقرر </th>
<th class="text-center table-primary" scope="col"> النصفي الاول</th>
<th class="text-center table-primary" scope="col"> نصفي الثاني</th>
<th class="text-center table-primary" scope="col">النهائي </th>
<th class="text-center table-primary" scope="col">المجموع </th>
<th class="text-center table-primary" scope="col">التقدير </th>
<th class="text-center table-primary" scope="col">عمليات </th>
</tr>
</thead>
<tbody>
<?php
include 'database.php';
include 'navbar.php';
$sql="select *from student";
$resault=mysqli_query($conn,$sql);
$resault=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($resault))
{
$id=$row['id'];
$s= ($row['mid_exam']+$row['fir_exam']);
$total=($s+$row['final']);
$grade="";
if($total<50)
{
$grade= "راسب";
}
elseif($total>=50 && $total<=64)
{
$grade= "مقبول";
}
elseif($total>=65 && $total <=74)
{
$grade= "جيد";
}
elseif($total>=75 && $total <=84)
{
$grade= "جيد جدا";
}
elseif($total>=85 && $total <=100)
{
$grade= "ممتاز";
}
echo '<tr >
<td class="text-center "> '.$row['id'].' </td>
<td class="text-center "> '.$row['id_code'].' </td>
<td class="text-center "> '.$row['fname'].' </td>
<td class="text-center "> '.$row['course_name'].' </td>
<td class="text-center"> '.$row['course_code'].' </td>
<td class="text-center"> '.$row['mid_exam'].' </td>
<td class="text-center"> '.$row['fir_exam'].' </td>
<td class="text-center"> '.$row['final'].' </td>
<td class="text-center"> '. $total .' </td>
<td class="text-center"> '. $grade .' </td>
<td class="text-center"> <button class="btn btn-primary my-3"> <a href="update.php?updateid='.$id.'" class="text-light text-decoration-none"> تعديل</a> </button>
<button class="btn btn-danger "> <a href="delete.php?deleteid='.$id.'" class="text-light text-decoration-none">حدف </a> </button>
<button class="btn btn-success " id="download" onclick="printPage(10)> تحميل</button>
</td>
</tr>';
}
?>
</tbody>
</table>
</div>
<script>
function printPage(id) {
// استخدام XMLHttpRequest لجلب محتوى الصفحة الخارجية
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// إنشاء نافذة جديدة تحتوي على محتوى الصفحة
var printWindow = window.open('', '_blank');
printWindow.document.write(xhr.responseText);
// انتظر حتى يتم تحميل الصفحة بشكل كامل ثم قم بطباعتها
printWindow.onload = function() {
printWindow.print();
};
}
};
xhr.open('GET', 'localhost/IT/print-page.php?id=' + id, true);
xhr.send();
}
</script>
</body>
</html>