I have a working resultset that is looped through during runtime to present a list of authors and links. Works correctly. I need to be able to display this same dataset two times in the same page. I'd rather not run the same query twice. How can I set the resultset (the display output shown below) as a var, and get the same output at both presentation points? I saw something a while back about using a for each loop, but not sure how to do that.
The query:
if($stmtr = mysqli_prepare($link, $sql8)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmtr, "s", $param_stripurlslash);
// Set parameters
$param_stripurlslash = $stripurlslash;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmtr)){
$resultAuthor = mysqli_stmt_get_result($stmtr);
$usera = mysqli_fetch_assoc($resultAuthor, MYSQLI_ASSOC);
} else {
echo "Oops! Something went wrong. Please try again later.";
}
}
The display output:
<?php
while ($row = mysqli_fetch_assoc($resultAuthor)) {
if ($row['book_author_first_name_only'] == 0 ) {
echo "<a class='fw-bold author-link' href='#" . $row['book_id'] . "'>" . $row['book_author_first_name'] . ' ' . $row['book_author_last_name'] . "</a>";
} else {
echo "<a class='fw-bold author-link' href='#" . $row['book_id'] . "'>" . $row['book_author_first_name'] . "</a>";
}
}
?>