我是一个学习型程序员,我有一个问题。
我的网站上有一个HTML表格,并用MySql中的数据填充它。
现在,我想按日期对表格进行排序,因此我希望表格顶部的最近日期。
我该怎么做(我的日期格式是[dd.mm]没有年份)
例如,使用ORDER BY方法,01.11是第一个条目,而不是23.10之后。
我的代码:
我希望你能帮助我,因为我没有得到。
<!DOCTYPE html>
<html>
<head>
<title>lll</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<script type="text/javascript">
function eintragen(){
window.location="http://lll.bplaced.net/eintragen.php"
}
</script>
</head>
<body>
<p class="headertext">Online lll</p>
<hr><br>
<?php
$servername = "localhost";
$username = "kllllf";
$password = "lll";
$dbname = "kll";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
}
$rows = 0;
$sql = "
SELECT
*
FROM
lll
";
$query = mysqli_query($conn, $sql);
$num = mysqli_num_rows($query);
echo "<table name=\"table\"border=\"1\">";
echo "<tr>";
echo "<td align=\"center\" valign=\"middle\" width=\"150px\" height=\"50px\">Bis Wann</td>";
echo "<td align=\"center\" valign=\"middle\" width=\"150px\">Fach</td>";
echo "<td align=\"center\" valign=\"middle\" width=\"350px\">lll</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=\"center\" valign=\"middle\" height=\"50px\">× × ×</td>";
echo "<td align=\"center\" valign=\"middle\">× × ×</td>";
echo "<td align=\"center\" valign=\"middle\">× × ×</td>";
echo "</tr>";
while($row = mysqli_fetch_assoc($query)){
$fach = $row['Fach'];
$ha = $row['Hllln'];
$ende = $row['Ende'];
if($ende < date("d.m")) {
$sqls = "DELETE FROM hlllll WHERE Ende='$ende';";
if(!mysqli_query($conn, $sqls)){
echo "<p>Es gab keine älteren Hlllll</p>";
}
}
echo "<tr>";
echo "<td align=\"center\" valign=\"middle\" height=\"50px\">".$ende."</td>";
echo "<td align=\"center\" valign=\"middle\">".$fach."</td>";
echo "<td align=\"center\" valign=\"middle\">".$ha."</td>";
echo "</tr>";
}
echo "</table>";
echo "<br />";
echo "<button type=\"button\" onclick=\"eintragen()\">Hlllllln eintragen?</button>";
?>
</body>
</html>