我可以在php中编辑mysqli_result对象吗? [英] Can I edit mysqli_result object in php?

查看:66
本文介绍了我可以在php中编辑mysqli_result对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从成功查询中获得了mysqli_result对象

I got mysqli_result object from successfully query

我想使用if语句修改此mysqli_result对象.

I wanna modify this mysqli_result object using if statement..

 $party_set = find_all_parties(); //mysqli_result object

 while($party = mysqli_fetch_assoc($party_set)){
     $locArr =split(",",$party["loc"]);    
     $lat = $locArr[0];
     $lng = $locArr[1]; 

     if(distance($currentLat,$currentLng,$lat,$lng) > $seletedDistance ){             
         //I want remove the row if this condition is true             
     }
 }

如何修改$party_set?

推荐答案

您不能修改mysqli结果对象.该对象只是一个句柄,可让您访问MySQL服务器上的MySQL结果集.您也不能更改它.您的选择是:

You cannot modify a mysqli result object. That object is just a handle that lets you access the MySQL result set on the MySQL server. You cannot change that either. Your options are:

  1. 将数据从结果对象获取到数组中,例如$data[] = mysqli_fetch_assoc($result);.然后,这是一个普通数组,您可以根据需要进行修改.如果您要循环执行此操作,只需不要,如果您不喜欢它,则将该行放入数据数组中.
  2. 使用WHERE子句进行查询,该子句从头开始排除不需要的行.
  3. 如果您要完全删除数据库中的特定行,则需要执行单独的DELETE FROM ..查询,仅将其从结果集中删除将不会执行任何操作.同样,您可以使用适当的WHERE子句轻松地一次性完成此操作,例如DELETE FROM .. WHERE (lat, lon, something something..).
  1. Get the data from the result object into an array, e.g. $data[] = mysqli_fetch_assoc($result);. It is then a normal array you can modify as you wish. If you're doing this in a loop, simply don't put the row into your data array if you don't like it.
  2. Make a query with a WHERE clause that excludes the unwanted rows from the beginning.
  3. If you mean that you want to delete specific rows from the database entirely, you need to do a separate DELETE FROM .. query, just removing it from the result set would do nothing. Again, you can do this very easily in one go with a proper WHERE clause, e.g. DELETE FROM .. WHERE (lat, lon, something something..).

这篇关于我可以在php中编辑mysqli_result对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆