我對PHP和SQL相當陌生,所以請對我輕鬆點。我將如何去迴應我在我的數據庫中創建的屬性表中的行?PHP:如何回顯數據庫中的行?
<?php
//CREATE CONNECTION
$servername = "localhost";
$username = "root";
$password = "root";
$conn = new mysqli($servername, $username, $password);
// CHECK THE CONNECTION
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// CREATE ESTATE AGENTS DATABASE
$sql = "CREATE DATABASE IF NOT EXISTS estate_agents";
if ($conn->query($sql) === TRUE) {
$dbname= "estate_agents";
$newConnection = new mysqli($servername, $username, $password,$dbname);
//CREATE PROPERTIES TABLE
$sql = "CREATE TABLE IF NOT EXISTS properties (
property_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
property_name VARCHAR(50) NOT NULL,
property_cost VARCHAR(50) NOT NULL,
property_description VARCHAR(500) NOT NULL
)";
if ($newConnection->query($sql) === TRUE) {
}
else {
echo "Error creating table: " . $newConnection->error . "</br>";
}
}
else {
echo "estate_agents not functional: " . $newConnection->error . "</br>";
}
?>
你有沒有嘗試這樣做呢? – Mattia
你需要做的第一件事是'選擇'一些行。 –
你甚至在你的屬性表中有行嗎? –