PHP
- 2 ответа
- 0 вопросов
0
Вклад в тег
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table>
<?php
$field = 'Alphabetic';
$sort = 'DESC';
if (isset($_GET['sort']) && isset($_GET['field'])) {
$getSort = $_GET['sort'];
$getField = $_GET['field'];
if ($getSort == 'desc' || $getSort == 'asc') {
$field = $getField;
$sort = $getSort;
}
}
?>
<a href="?field=Numeric&sort=desc">Numeric</a> <br/>
<a href="?field=Numeric&sort=asc">Numeric</a>
<?
$sql = "SELECT * FROM test_table2 ORDER BY $field $sort";
echo "<table>";
echo "<table><tr><th>Alphabetic</th><th>Numeric</th><th>Date</th><th>Unsortable</th></tr>";
$sql = mysqli_query($db, $sql);
while ($result = mysqli_fetch_array($sql))
{
echo "<tr><td>".$result['Alphabetic']."</td><td>".$result['Numeriс']."</td><td>".$result['Date']."</td><td>".$result['Unsortable']."</td></tr>";
}
echo "</table>";
?>
</table>
</body>
</html>