Php 如何在重定向到详细站点并再次返回后保存用户筛选输入
因此,我建立了一个简单的php站点,用户可以在其中过滤表的内容。还包括一个详细信息链接,每个条目都会将用户重定向到只显示所用条目详细信息的站点。详细信息网站基本上只显示特定信息和一个按钮,让用户返回到原始网站 我的问题是,我想保存用户在转发到详细网站时的过滤输入,以及当用户单击链接返回到原始网站时的过滤输入。理想情况下,如果可能的话,我想用Php 如何在重定向到详细站点并再次返回后保存用户筛选输入,php,redirect,get,Php,Redirect,Get,因此,我建立了一个简单的php站点,用户可以在其中过滤表的内容。还包括一个详细信息链接,每个条目都会将用户重定向到只显示所用条目详细信息的站点。详细信息网站基本上只显示特定信息和一个按钮,让用户返回到原始网站 我的问题是,我想保存用户在转发到详细网站时的过滤输入,以及当用户单击链接返回到原始网站时的过滤输入。理想情况下,如果可能的话,我想用$\u GET来完成 这是我的index.php: <p align="center"><a href='index.php?filterf
$\u GET
来完成
这是我的index.php:
<p align="center"><a href='index.php?filterfeld="<?php echo $_GET['filterfeld']?>"'><button>Zurück</button></a></p>
index.php:
<h1>Benutzerdaten anzeigen</h1>
<div class="filter">
<label class="labelf">Filtern:</label>
<input id="filterfeld" name='filterfeld' onkeyup="filterRows()" value =<?php echo $_GET['filterfeld']; ?>>
<button id="reset" class="reset" value="Reset" onclick="window.location.reload(true)">RESET</button>
</div>
<?php
$servername = "localhost";
$username = "root";
$username = "root";
$password = "";
$dbname = "php13";
$filter_value = isset($_GET['filterfeld']) ? $_GET['filterfeld'] : "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM user";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table align='center' id='ftable' class='ftable'><tr><th>ID</th><th>Vorname</th><th>Nachname</th><th>E-Mail</th><th>Telefon</th><th>Geburtsdatum</th><th>Straße</th><th>Details</th></tr>";
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<td></td><tr><td>" . $row["id"] . "</td><td>" . $row["firstname"] . "</td><td>" . $row["lastname"] . "</td>
<td>" . $row["email"] . "</td><td>" . $row["phone"] . "</td><td>" . $row["birthdate"] . "</td><td>" . $row["street"] . "</td><td><a href='singleentry.php?id=" .$row["id"]."&filterfeld=". $filter_value . "' class='details'>Details</a></td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
</form>
Benutzerdaten-anzigen
过滤器:
所以你要记住页面的“状态”
你有很多选择,但要尽量接近你发布的内容:
将过滤器选项发布到其他站点,并在返回时包含它们。最后,您将在(GET或post)中使用编码的过滤器选项向其他站点发送帖子。
假设您发布到details.php
获取:
重要提示:必须更改表单的操作以包含新的filteroptions(仅存在于javascript中),或者(更容易)更改隐藏的formelement以包含选项
在details.php上,必须使“后退”按钮包含先前收到的过滤器选项
var input, filter, table, tr, td, cell, i, j;
input = document.getElementById("filterfeld");
filter = input.value.toUpperCase();
table = document.getElementById("ftable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
tr[i].style.display = "none";
td = tr[i].getElementsByTagName("td");
for (var j = 0; j < td.length; j++) {
cell = tr[i].getElementsByTagName("td")[j];
if (cell) {
if (cell.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
}
}
}
}
}