PHP和mysqli:从数据库的HTML表

问题描述:

我试图从数据库中提取几个字段的数据,并使用mysqli填充HTML表。我试图研究这个问题已经提出了解决方案,使用mysql或似乎混合mysql与mysqli。我一直在尝试使用API​​来找到可能工作的函数,但似乎不能获得显示表。任何建议,将不胜感激。

I'm trying to pull the data for a couple of fields out of a database and populate an HTML table using mysqli. My attempts to research the problem have come up with solutions that either use mysql or seem to mix mysql with mysqli. I've been attempting to use the API to find functions that might work, but can't seem to get the table to display. Any suggestions would be appreciated.

<?php
ini_set('display_errors', 'On');
ini_set('display_startup_errors', 'On');
error_reporting(E_ALL);

$mysqli = new mysqli("$dbhost", "$dbuser", "$dbpass", "$dbname");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if (!$stmt = $mysqli->query("SELECT aid, aname FROM actor_info")) {
    echo "Query Failed!: (" . $mysqli->errno . ") ". $mysqli->error;
}

if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}

if (!$stmt->bind_result($aid, $aname)) {
    echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}

echo "ACTOR INFORMATION";
echo "<table border='1' cellpadding='2' cellspacing='2'";
echo "<tr><td>ID</td><td>NAME</td>";
while ($row = mysqli_fetch_array($stmt)) {
        echo "<tr>";
        echo "<td>".$aid."</td>";
        echo "<td>".$aname."</td>";
        echo "</tr>";
}
else {
    echo "No records found";
}
$stmt->free();
$mysqli->close();
?>


while ($row = mysqli_fetch_array($stmt)) {
    echo "<tr>";
    echo "<td>" . $row["aid"] . "</td>";
    echo "<td>" . $row["aname"] . "</td>";
    echo "</tr>";
}