<!DOCTYPE html>
<html lang="en">
<head>
  <title>View Company</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="background-image: url('../../images/fibermat.gif'); background-size: cover; background-repeat: no-repeat; background-attachment: fixed;">

<div class="container mt-3">
<?php
include("../../include/dbconnect.php");

echo '<h2><center><b>View Area</b></center></h2>';
$query = "select distinct record,location,state,country,areacode from area  group by record order by location";

$result = mysqli_query($conn, $query);

if (!$result) {
    die("Query failed: " . mysqli_error($conn));
}

$number_cols = mysqli_num_fields($result);

echo '<table border="1" class="table table-striped">';
echo '<tr align="center">';

for ($i = 0; $i < $number_cols; $i++) {
    $fieldInfo = mysqli_fetch_field_direct($result, $i);
    echo '<th>' . $fieldInfo->name . '</th>';
}

echo '</tr>';

while ($row = mysqli_fetch_assoc($result)) {
    echo '<tr align="left">';
    echo '<td>';
    
    if (!isset($row['record'])) {
        echo 'NULL';
    } else {
        echo '<a href="editview.php?record=' . $row['record'] . '"><img src="../../images/b_edit.png"></a>';
    }

    foreach ($row as $key => $value) 
    {
       if ($key != 'record') {
        echo '<td>';
        echo $value;
       }
    }
    
    echo '</tr>';
}

echo '</table>';

echo '<br><br><font size="1"><center><a href="index.html">Return to index page</a></center></font>';
?>
</div>

</body>
</html>
