基于某些条件,我希望能够从php中的$mysqli
对象返回的结果集中删除一行。有谁知道怎么做?
<?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
....
?>
答案 0 :(得分:2)
您无法对结果集执行此操作。你最好的选择是建立一个阵列。
<?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
....
?>