<?php
include 'db.php';
$student_id = intval($_GET['student_id']);

$q = mysqli_query($conn, "
    SELECT problem_type, problem_note, problem_date, problem_count, admin_name
    FROM admin_behavior
    WHERE student_id='$student_id'
    ORDER BY problem_date DESC
");

if (!$q || mysqli_num_rows($q) == 0) {
    echo "<p style='color:red;text-align:center;'>❌ لا توجد مشاكل لهذا الطالب.</p>";
    exit;
}

echo "<table>
<tr><th>نوع المشكلة</th><th>التاريخ</th><th>عدد المرات</th><th>الملاحظات</th><th>المسؤول</th></tr>";
while($r = mysqli_fetch_assoc($q)){
    echo "<tr>
        <td>".htmlspecialchars($r['problem_type'])."</td>
        <td>".htmlspecialchars($r['problem_date'])."</td>
        <td>".(int)$r['problem_count']."</td>
        <td>".htmlspecialchars($r['problem_note'])."</td>
        <td>".htmlspecialchars($r['admin_name'])."</td>
    </tr>";
}
echo "</table>";
?>
