是否有任何方法可以在while loop
下定义变量并将其打印在while loop
上方
像这个
print $catName
while ($b = mysqli_fetch_assoc($results)) {
$catName = $b['cat'];
}
编辑
$getBooks = $db->prepare('SELECT
id, cat, instituteId, title, cover, authorName FROM books_library WHERE instituteId=? AND cat=?');
$getList = array();
$getBooks->bind_param('ii', $inId, $cid);
if ($getBooks->execute()) {
$libResults = $getBooks->get_result();
$getList[] = $libResults;
?>
HTML代码来这里
<h3 class="marginBottom8px margin-top_30px text-bold text-danger"><?php echo catName ?></h3>
然后WHILE循环
while ($book = mysqli_fetch_assoc($libResults)) {
$bokId = $book['id'];
$bookTitle = $bokId['title'];
$catName = $bokId['cat'];
$catName = $bokId['cat'];
现在在while loop
下我得到了$catName
我如何在<h3></h3>
中echo
while块之后,将h3
html放入变量中并打印。
$myHtml = '<h3 class="marginBottom8px margin-top_30px text-bold text-danger">'
. $catName . '</h3>';
print $myHtml;
不要像那样混合html和php。
我认为这就是基于编辑后的问题
while ($book = mysqli_fetch_assoc($libResults)) {
echo '<h3>' . $book['cat'] . '</h3>';
}