tags:

views:

86

answers:

3

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

A: 

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;
Jonathan Sampson
+1  A: 

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.

nickf
A: 

You could load the original result set into a temporary table, then run additional queries against it.

Rob Drimmie