我正在开发一个在网站上使用的应用程序。该应用程序允许您将作业提供添加到数据库,以将其发布到网站和社交媒体上。我已经做了很多,但现在我正在尝试制作一个排序菜单。在我的数据库中,我有一行名为Status。状态是一个包含数据打开和关闭的枚举,所以我想有一个排序选项。我想对Open,Closed等所有人进行排序。
我已经有了一张桌子,如果有可能,我希望看到现有桌子上的更改,但我不知道如何做到这一点。有人可以帮我这个吗?我使用HTML,PHP和数据库PHPMyAdmin。这是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
td {
border: 1px solid black;
width: 120px;
}
</style>
</head>
<body>
<h2>Jobs Overview (Admin)</h2>
<form action="/action_page.php">
<select id="sorting">
<option value="All" >All</option>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
<br><br>
<?php
include 'Connection.php';
echo "<table>";
echo "<tr>";
echo "<th>" . "jid" . "</th>";
echo "<th>" . "role" . "</th>";
echo "<th>" . "type" . "</th>";
echo "<th>" . "availability" . "</th>";
echo "<th>" . "location" . "</th>";
echo "<th>" . "status" . "</th>";
echo "<th>" . "Verwijder?" . "</th>";
echo "</tr>";
$select = "SELECT * FROM test";
$result = mysql_query($select);
if($result) {
} else {
echo "Error! <br>";
echo mysql_error();
}
while($data = mysql_fetch_assoc ($result)) {
echo "<tr>";
echo "<td>" . $data["jid"] . "</td>";
echo "<td> <a href='jobsupdate.php?jid=" . $data["jid"] . "'>" . $data["role"] . " </a></td>";
echo "<td>" . $data["type"] . "</td>";
echo "<td>" . $data["availability"] . "</td>";
echo "<td>" . $data["location"] . "</td>";
echo "<td>" . $data["status"] . "</td>";
echo "<td> <a href = 'jobsdelete.php?jid=" . $data["jid"] . "' onClick=\"return confirm('Weet je zeker dat je deze record wil verwijderen?');\"><center>Verwijder</center></a></td>";
}
echo "</tr>";
echo "</table>";
?>
<br><br>
<a href="jobsadmin.php">Vacatures Toevoegen</a>
</body>
</html>
提前致谢
答案 0 :(得分:1)
您可以将HTML类添加到open
和closed
个作业。
while($data = mysql_fetch_assoc ($result)) {
echo "<tr>";
echo "<td>" . $data["jid"] . "</td>";
echo "<td> <a href='jobsupdate.php?jid=" . $data["jid"] . "'>" . $data["role"] . " </a></td>";
echo "<td>" . $data["type"] . "</td>";
echo "<td>" . $data["availability"] . "</td>";
echo "<td>" . $data["location"] . "</td>";
if ($data["status"] == 0) {
echo "<td class='open'>" . $data["status"] . "</td>";
} else {
echo "<td class='closed'>" . $data["status"] . "</td>";
}
echo "<td> <a href = 'jobsdelete.php?jid=" . $data["jid"] . "' onClick=\"return confirm('Weet je zeker dat je deze record wil verwijderen?');\"><center>Verwijder</center></a></td>";
}
echo "</tr>";
echo "</table>";
之后,您必须编写一个jquery脚本来隐藏作业.on
change
。
$('#sorting').on('change', function(){
var status = $('#sorting:selected').val();
if (status == "Open") {
$('.closed').hide();
} else if (status == "Closed") {
$('.open').hide();
} else if (status == "All"){
$('.closed').show();
$('.open').show();
}
});
我希望这能解决你的问题。
答案 1 :(得分:0)