0

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

<?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();
?>
4

1 回答 1

1
while ($row = mysqli_fetch_array($stmt)) {
    echo "<tr>";
    echo "<td>" . $row["aid"] . "</td>";
    echo "<td>" . $row["aname"] . "</td>";
    echo "</tr>";
}
于 2013-02-18T02:51:53.553 回答