PHP MySQLi is just returning one row in JSON
问题 I am working on the below code. Why am I getting only one row in my JSON output? $items = []; if ($stmt = $this->conn->prepare("SELECT * FROM $tbl")) { $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $items = $row; } $stmt->free_result(); $stmt->close(); } $this->conn->close(); } echo json_encode($items); 回答1: This happens because you are going through the rows and assigning each of them to $items : while ($row = $result-