[英]MySQL/PHP - Query a result set?
I have a result set that I want to filter. 我有一个要过滤的结果集。
Question is how can I run a query on a result set? 问题是如何在结果集上运行查询?
Using PHP and MySQL. 使用PHP和MySQL。
Thanks 谢谢
You can either add a more specific WHERE
clause in your original SQL, or, if that's infeasible you could do this: 您可以在原始SQL中添加更具体的WHERE
子句,或者,如果这样做不可行,则可以执行以下操作:
SELECT `field1`, `field2`
FROM (
SELECT * FROM `myTable`
)
...adding in your search criteria in the appropriate places. ...在适当的位置添加搜索条件。
You really should include the filter into the query itself, rather than pulling back a bunch of data and then filtering. 您确实应该将过滤器包含在查询本身中,而不是先拉回一堆数据然后进行过滤。 That being said, you can filter the output as you cycle through the records. 话虽如此,您可以在循环浏览记录时过滤输出。 An example follows: 下面是一个示例:
$output = "";
while ($row = mysql_fetch_array($rst)) {
if ($row["col1"] == 0) continue; // ignore records where col1 is 0
$output .= "<p>".$row["col2"]."</p>";
}
print $output;
您可以将原始结果集加载到临时表中,然后对它运行其他查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.