So, this is not a problem than need solving, but rather a question out of curiosity and want of clarification. A was struggling with a piece of php/mysqli and while debugging and splitting the code up I discovered that my code was working, just not the way I wrote it.
Initial code (Not working)
$result = $mysqli -> query("SELECT nick FROM userdata WHERE id=".$_SESSION['uid']);
// ... error checking here ...
for($i = $result -> num_rows - 1; $i >= 0; $i--){
$result -> data_seek($i);
$nick = ($result -> fetch_assoc())['nick']; // crash
}
Final code (Working)
$result = $mysqli -> query("SELECT nick FROM userdata WHERE id=".$_SESSION['uid']);
// ... error checking here ...
for($i = $result -> num_rows - 1; $i >= 0; $i--){
$result -> data_seek($i);
$row = $result -> fetch_assoc(); // working
$nick = $row['nick']; // working
}
So, can anyone enlighten me as to why the first code simply breaks for me?
Best regards.