Reputation:
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.
Thanks
Upvotes: 0
Views: 3394
Reputation: 1586
You could load the original result set into a temporary table, then run additional queries against it.
Upvotes: 0
Reputation: 546025
You can either add a more specific WHERE
clause in your original SQL, or, if that's infeasible you could do this:
SELECT `field1`, `field2`
FROM (
SELECT * FROM `myTable`
)
...adding in your search criteria in the appropriate places.
Upvotes: 3
Reputation: 268344
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;
Upvotes: 1