gpt4 book ai didi

php - 如何从 php mysqli 的结果集中删除行

转载 作者:行者123 更新时间:2023-11-29 07:57:49 25 4
gpt4 key购买 nike

基于某些条件,我希望能够从 php.ini 中的 $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
....
?>

最佳答案

您不能对结果集执行此操作。你最好的选择是构建一个数组。

<?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
....
?>

关于php - 如何从 php mysqli 的结果集中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24658465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com