要使用PHP編寫數據庫報表,你需要按照以下步驟進行:
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("連接失敗: " . $conn->connect_error);
}
$sql = "SELECT * FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 處理查詢結果
} else {
echo "0 結果";
}
while ($row = $result->fetch_assoc()) {
// 輸出或處理數據
}
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "</tr>";
}
echo "</table>";
$conn->close();
這樣,你就可以使用PHP編寫數據庫報表了。根據你的需求,你可能需要進一步優化報表的結構和樣式,或者添加其他功能來增強報表的功能。