عليك القيام بالتالي:
إزالة علامات <?php المتداخلة أي الزائدة في الكود حيث نضعها في بداية كود php فقط ثم نغلق ذلك الجزء من خلال ?>
استخدام PDO::fetchAll() لجلب جميع النتائج دفعة واحدة لتحسين الكفاءة.
استبدال mysql_fetch_assoc() بـ foreach للتنقل عبر الصفوف المسترجعة.
إغلاق الاتصال بنقل سطر connection = null خارج الحلقة لضمان الإغلاق الصحيح.
التعامل مع الأخطاء بإضافة كتلة try...catch وتمكين التعامل مع الأخطاء باستخدام PDO::ATTR_ERRMODE.
الكود بعد التعديل:
<!DOCTYPE html>
<html lang="ar">
<head>
<link rel="icon" href="https://c0.klipartz.com/pngpicture/573/614/gratis-png-ng%C5%A9-hanh-s%C6%A1n-distrito-casa-apartamento-inmobiliaria-volta-redonda-venta-de-logotipos-de-bienes-raices.png" />
<title>موقع العقارات</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300&display=swap" rel="stylesheet">
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="home.css">
</head>
<body>
<?php
$server = 'DESKTOP-PJDLJNR';
$database = 'Legacy';
$username = '';
$password = '';
try {
$connection = new PDO("sqlsrv:Server=$server;Database=$database", $username, $password);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Enable error handling
$sql_query = 'SELECT * FROM Problemss';
$statement = $connection->query($sql_query);
$result = $statement->fetchAll(PDO::FETCH_ASSOC); // Fetch all results
} catch (PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
?>
<table border="1" width="100%">
<tr>
<th>تم</th>
<th>الحلول</th>
<th>المشكلة</th>
<th>م</th>
<th>الرقم</th>
</tr>
<?php foreach ($result as $row) { ?>
<tr>
<td><?php echo $row['تم'] ?></td>
<td><?php echo $row['الحلول'] ?></td>
<td><?php echo $row['المشكلة'] ?></td>
<td><?php echo $row['م'] ?></td>
<td><?php echo $row['الرقم'] ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>