I\'m using a prepared statement to SELECT *
from a MySQL table and I\'m not sure how to use while($row = mysqli_fetch_array($stmt))
to loop through
Nothing wrong with Darwin's answer, but wanted to point out PDO as an alternative with much lighter syntax:
PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$link = new PDO("mysql:host=$host;dbname=$db", $username, $password, $options);
$stmt = $link->prepare("SELECT * from `wp_posts` WHERE ID=?");
$stmt->execute([$pid]);
$result = $stmt->fetchAll();
// Now you have a plain array to work with, database work is over
foreach ($result as $row):
?>
=$row["post_title"]?>
=$row["post_content"]?>
No need for any binding at all, and personally I find it much easier to work with.