<?php
# deze file maakt de connectie met de database
require ('connect.php');
function display_table ($hmboiten, $dvds) {
# haal de namen en het aantal velden op
$fields = mysql_list_fields ($hmboiten, $dvds);
$columns = mysql_num_fields ($fields);
# als er op een kolomkop geklikt is, is de naam van die kolom
# beschikbaar via $_GET
if (isset ($_GET['order_by'])) {
$order_by = $_GET['order_by'];
}
else {
$order_by = 'id';
}
if (isset ($_GET['order_type']) && !isset ($_GET['action'])) {
$order_type = $_GET['order_type'];
if ($order_type == 'ASC') {
$order_type = 'DESC';
}
else {
$order_type = 'ASC';
}
}
else {
$order_type = 'ASC';
}
echo '<table>';
echo '<tr>';
echo '<th>edit</th>';
echo '<th>delete</th>';
# de titelrij van de tabel in elkaar zetten
# zorgen dat de kolomkoppen aanklikbaar zijn
for ($i = 0; $i < $columns; $i++) {
echo "\n";
echo '<th>';
$fieldname = mysql_field_name ($fields, $i) ;
echo "<a href=\"?order_by=$fieldname&order_type=$order_type\">$fieldname</a>";
echo '</th>';
}
$sql = "SELECT *
FROM $dvds
ORDER BY $order_by $order_type";
$res = mysql_query ($sql) or die (mysql_error ());
while ($row = mysql_fetch_array ($res)) {
echo "\n";
echo '<tr>';
# via deze links kun je de pagina uitbreiden met een delete of een edit-mogelijkheid
echo "<td><a href=\"?action=edit&id=$row[id]&order_by=$order_by\">edit</a></td>";
echo "<td><a href=\"?action=delete&id=$row[id]&order_by=$order_by\">delete</a></td>";
for ($i = 0; $i < $columns; $i++) {
echo '<td>';
echo $row[$i];
echo '</td>';
}
echo '</tr>';
}
echo '</tr>';
echo '</table>';
}
?>
<html>
<head>
<title>ppm</title>
<style type="text/css"> <!-- A:link {color:"#000060"; text-decoration:none} a:hover {color:"#000060"; text-decoration:underline}
A:visited {color:"#000060"; text-decoration:none} --> </style>
</head>
<body>
<h1>Tabelletje</h1>
<?php display_table(); ?>
</body>
</html>