I got mysqli_result object from successfully query
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
}
}
How can I modify $party_set
??
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:
$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.WHERE
clause that excludes the unwanted rows from the beginning.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..)
.you don't need to modify the original object but to create a new array :
$party_set = find_all_parties(); //mysqli_result object
$new_party_set = array();
while($party = mysqli_fetch_assoc($party_set)){
$locArr =split(",",$party["loc"]);
$lat = $locArr[0];
$lng = $locArr[1];
if(distance($currentLat,$currentLng,$lat,$lng) <= $seletedDistance ){
$new_party_set[] = $party;
}
}
if you need to modify the database as well and not only the php set, then run another query using IN operator .
Thank you every one.. I solve this problem by very silly way..
I made a new query string like this..
function checkDistance($currentLat,$currentLng,$setDistance){ global $connection; $party_set = find_all_parties(); //mysqli_result object $query = "SELECT * "; $query .= "FROM party "; $query .= "WHERE ";
while($party = mysqli_fetch_assoc($party_set)){ $locArr =split(",",$party["loc"]); $lat = $locArr[0]; $lng = $locArr[1]; $id= $party["id"]; //세팅 된 거리보다 거리가 작으면 if(distance($currentLat,$currentLng,$lat,$lng) <= $setDistance ){ $query .= "id = {$id} OR "; } } //delete last "OR " $query = substr($query, 0, strlen($query) - 3); echo $query; $dt_party_set = mysqli_query($connection,$query); confirm_query($dt_party_set); return $dt_party_set; }
anyway,, thank you very much
and after my project done I'll retry using the way what you recommended ...good luck everyone