我試圖將$countries
連接到一個數組,該數組將顯示我的數據庫中的所有數據,它只顯示我輸入的最後一個數據。無論如何我都可以顯示他們全部?如何使用數組顯示數據庫中的所有數據
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT product_id, product_name , quantity FROM inventory";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$tom = array(" ". $row["quantity"] . $row["product_name"]);
$countries = $tom;
}
} else {
echo "0 results";
}
$conn->close();
'$ countries [] = $ tom;' – Alex