在块引用中显示数据库数据

时间:2017-11-10 20:23:10

标签: php sql twitter-bootstrap

我想在blockquote bootstrap 4标签中显示数据库数据3列。列长度​​10,带有额外的id列(非空自动增量)。它显示空白行和空白源行。没有文字。知道如何做到这一点。提前致谢

我确实尝试了类似(php,bootstrap和sql代码)

    //database connection file
    <?php
    $dbc = mysqli_connect('localhost', 'achy', 'achy');
    if (!$dbc) {
       die('Databse Not Connected :' . mysqli_error());
     }

     //Select Database
     $db_selected = mysqli_select_db($dbc, "test");
     if (!$db_selected) {
      die ("Databse Not connected : " . mysqli_error());
     }
     ?>

    $sql = "SELECT * FROM test";
        $result = mysqli_query($dbc, $sql);
        $resultCheck = mysqli_num_rows($result);

        if($resultCheck > 0) {
            while($row = mysqli_fetch_assoc($result))
            {

            }
        }

        ?>  
//bootstrap tag  
    <blockquote class="blockquote">
      <p class="mb-0 lead"><?php echo $row['name']; ?></p>
      <footer class="blockquote-footer"><?php echo $row['name2']; ?> <cite title="Source Title"><?php echo $row['product']; ?></cite></footer>
    </blockquote>

刚试过:

 <?php

        $sql = "SELECT * FROM test";
        $result = mysqli_query($dbc, $sql);
        $resultCheck = mysqli_num_rows($result);

        if($resultCheck > 0) {
            while($row = mysqli_fetch_assoc($result)) ?>

    <blockquote class="blockquote">
      <p class="mb-0 lead"><?php echo $row['name']; ?></p>
      <footer class="blockquote-footer"><?php echo $row['name2']; ?><cite title="Source Title"><?php echo $row['product']; ?></cite></footer>
    </blockquote>

    <?php endwhile; ?>

Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE).....

1 个答案:

答案 0 :(得分:0)

在执行PHP样式时,需要在控制结构之后使用冒号,因此while($row = mysqli_fetch_assoc($result)): ?>可以正常工作