gpt4 book ai didi

PHP - 过滤表中的数据

转载 作者:可可西里 更新时间:2023-11-01 07:46:45 26 4
gpt4 key购买 nike

我需要有关如何过滤数据库中数据的帮助。我想要一个类似于 Excel 电子表格中的过滤器。

例如,我有关于如何从 w3school 获取数据的示例代码关于如何从数据库中选择数据。这是我的示例代码:

 <?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("TableTest", $con);

$result = mysql_query("SELECT * FROM Colors ");

echo "<table border='1'>
<tr>
<th>Colors</th>
<th>Type</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['colors'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

enter image description here

我也找到了这个sample在 w3school 中也是如此,但我不想使用下拉列表来过滤数据库。

我想让它像一个 excel 过滤器。当我选择“颜色”列以过滤“红色”时,它将仅显示红色。所以我想知道是否有人可以帮助我如何开始。

谢谢大家

最佳答案

$result = mysql_query("SELECT * FROM Colors WHERE color='Red'");

关于PHP - 过滤表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6306807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com