如何将行回显到我的html中?

0 html php mysql

我正在尝试做下一件事:

从表格电影中选择行标题,并显示<h3></h3>标签之间的答案.

这就是我现在拥有的.

$sql = "SELECT title FROM movies";
$result = mysqli_query($mysqli, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result))  


?>


<div class="grids">
<div class="grid">
                    <h3>
<?php {
    echo "" . $row["title"]. "";
}
}?>
</h3>    
Run Code Online (Sandbox Code Playgroud)

2个div类正在代码中的某个地方结束.当我在h3标签之间添加纯文本时,它可以很好地工作.

这也很完美,但它并没有在我希望它的地方回应:

<?php

$sql = "SELECT title FROM movies";
$result = mysqli_query($mysqli, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
    echo "" . $row["title"]. " <br>";
}
} ?>
Run Code Online (Sandbox Code Playgroud)

我如何让它在标签之间回显?

提前致谢!

Jay*_*ard 5

在元素内部输出 -

<?php
$sql = "SELECT title FROM movies";
$result = mysqli_query($mysqli, $sql);
?>

<div class="grids">
<?php 
    if (mysqli_num_rows($result) > 0) {
    // output data of each row
       while($row = mysqli_fetch_assoc($result)) {
           echo '<div class="grid">';
           echo '<h3>' .  $row["title"] . '</h3>';
           // you can echo other info inside the grid
           echo '</div>';
       }
    } 
?>
</div><!-- ends grids -->
Run Code Online (Sandbox Code Playgroud)