0

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

1 Answer 1

1
while ($row = mysqli_fetch_array($stmt)) {
    echo "<tr>";
    echo "<td>" . $row["aid"] . "</td>";
    echo "<td>" . $row["aname"] . "</td>";
    echo "</tr>";
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.