I'm trying to get the mysqli_fetch_assoc()
to work with my $stmt
, but couldn't manage it to find any working method. The base code that I'm trying to do is to get the latitudine
and longitudine
from the table, 1 row at a time so I have implemented Haversine Formula to calculate the distances:
$stmt = $conn->prepare("SELECT latitudine, longitudine FROM alerte WHERE tip_problema = ?");
$stmt->bind_param("s", $problema);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows>0){
while($row = $stmt->mysqli_fetch_assoc()) {
$row[latitudine]= $latitudine1;
$row[longitudine]= $longitudine2;
...(rest of while);
}
but using this code, I got the error that says the mysqli_fetch_assoc()
has to be used with mysqli_result
, not mysqli_stmt
, so I started to change the code to achieve the mysqli_result
:
$stmt = $conn->prepare("SELECT latitudine, longitudine FROM alerte WHERE tip_problema = ?");
$stmt->bind_param("s", $problema);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows>0){
$result = $stmt->get_result();
while($row = $result->mysqli_fetch_assoc()) {
$row[latitudine]= $latitudine1;
$row[longitudine]= $longitudine2;
......
}
but once again, I get an error :
Fatal error: Uncaught Error: Call to a member function mysqli_fetch_assoc() on bool in ...
I tried to get out the $stmt->store_result;
that's before the if
statement but it generates this error:
Fatal error: Uncaught Error: Call to a member function execute() on bool in ..
The last major try was this:
$stmt = $conn->prepare("SELECT latitudine, longitudine FROM alerte WHERE tip_problema = ?");
$stmt->bind_param("s", $problema);
$stmt->execute();
$result = $stmt->get_result();
if($stmt->num_rows>0){
while($row = $result->mysqli_fetch_assoc()) {
$row[latitudine]= $latitudine1;
$row[longitudine]= $longitudine2;
....
}
And here, I do not receive any error, but the code gets past if($stmt->num_rows>0)
, thus not retrieving the rows 1 by 1.