Reputation: 18238
Based on some condition I want to be able to remove a row from the result set returned from the $mysqli
object in php. Does anyone know how to do that?
<?php
...
$result_set = $mysqli->query('select * from schema.table1;');
while ($row = $result_set->fetch_assoc()){
if (/* some condition */){
//remove this row from the result set
}
}
$result_set->data_seek(0);
//now the result set has less rows than it did to begin with
....
?>
Upvotes: 0
Views: 2213
Reputation: 42743
You can't do this to the result set. Your best bet would be to build an array instead.
<?php
...
$valid_results = array();
$result_set = $mysqli->query('select * from schema.table1;');
while ($row = $result_set->fetch_assoc()){
if (/* some condition */){
continue;
}
$valid_results[] = $row;
}
//do stuff with $valid_results
....
?>
Upvotes: 3