Moneybag 1 Posted April 28, 2019 Report Share Posted April 28, 2019 (edited) Boas malta Tou com um problema no meu código e não consigo listar uma tabela de uma base de dados MySql nesta função de PHP o seguinte código continua a dar echo de "0 results": function showLog($table, $mysqli) { if ($stmt = $mysqli->prepare("SELECT id, log_date, log_text FROM $table")) { $stmt->execute(); $result = $stmt->get_result(); if ($stmt->num_rows > 0) { while($row = $result->fetch_assoc()) { //echo "LOG ID: (" . $row["id"].") Date: ". $row["log_date"] . "│ TEXT: " . $row["log_text"]. "<br>"; } }else { echo "0 results"; } $stmt->close(); } } obrigado pela atenção Edited April 28, 2019 by Ascensao Link to post Share on other sites
Moneybag 1 Posted April 29, 2019 Author Report Share Posted April 29, 2019 entretanto encontrei a resposta no stackoverflow. Quote That's because fetch_assoc is not part of a mysqli_stmt object. fetch_assoc belongs to the mysqli_result class. You can use mysqli_stmt::get_result to first get a result object and then call fetch_assoc: $selectUser = $db->prepare("SELECT `id`,`password`,`salt` FROM `users` WHERE `username`=?"); $selectUser->bind_param('s', $username); $selectUser->execute(); $result = $selectUser->get_result(); $assoc = $result->fetch_assoc(); $selectUser = $db->prepare("SELECT `id`,`password`,`salt` FROM `users` WHERE `username`=?"); $selectUser->bind_param('s', $username); $selectUser->bind_result($id, $password, $salt); $selectUser->execute(); while($selectUser->fetch()) { //$id, $password and $salt contain the values you're looking for } Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now