PHP - 过滤表中的数据 [英] PHP - Filtering data in table

查看:74
本文介绍了PHP - 过滤表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



例如,我有如何从也在w3school中,但我不想用一个下拉列表过滤数据库。



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



感谢所有人

解决方案

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


I need help on how to filter data in a database. I want a filter like in the excel spreadsheet.

For example, I have this sample code on how to get data from w3school on how to select data from database. Here is my sample code:

 <?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);
?>

I also found this sample too in w3school, but I dont want to filter the database with a drop down.

I'd like to make it like an excel filter. When I select the column 'Colors' to filter on 'Red', it will display only the color red. So i was wondering if anyone could help me on how to start.

Thanks all

解决方案

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

这篇关于PHP - 过滤表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆