通过PHP将MySql中的项目插入HTML引导页


Insert items from MySql through PHP to HTML Bootstrap page

我正在尝试将这个PHP代码的结果匹配到这个Bootstrap HTML结构中。

到目前为止,我能够实现的是以3列布局打印数据库中的项目,但我不知道如何将这些结果与/info my bootstrap html"structure/table"相结合。我想我需要处理"id",并在每次"echo"(h4)之后递增它?但我对PHP还很陌生。谢谢你的任何实用建议。

PHP代码:

        // Run query on connection
        $query = "SELECT
                            product.id,
                            product.name as product_name,
                            product.price,
                            product.type
                FROM        pizza_project.product
                INNER JOIN  pizza_project.product_type on product.type = product_type.id
                where       product.type in (1,2)
                order by    product.type ASC, product.price ASC";

        $result = $con->query($query);
        ?>
        <table>
            <tr>
            <?php
           $split = 0;
           $id = $row['id']; // just an idea I think I need to start with
           if (mysqli_num_rows($result) > 0) {
                foreach ($result as $row) {
                    echo '<td>' . $row['product_name'] . ' ' . $row['id'] . '</td>';
                    $split++;
                    if ($split%3 == 0) {
                        echo '</tr> </tr>';
                    }
                }
            }  
            ?>
            </tr>        
        </table>
<?php                                                                                                                                                                   
$itemsInRow = 0;                                                                                                                                                        
foreach ($result as $row) {                                                                                                                                             
        if ($itemsInRow === 0)                                                                                                                                          
                echo "<div class='"row text-center'">";                                                                                                                 
        echo "<div class='"col-md-4'">";                                                                                                                                
        echo "<span class='"fa-stack fa-4x'">";                                                                                                                         
        echo "<img class='"product-image'" src='"" . $row['img'] . "'">";                                                                                               
        echo "</span>";                                                                                                                                                 
        echo "<h4 class='"service-heading'">" . $row['headline'] . "</h4>";                                                                                             
        echo "<p class='"text-muted'">" . $row['text']  . "</p>";                                                                                                       
        echo "</div>";                                                                                                                                                  
        if ($itemsInRow === 0)                                                                                                                                          
                echo "</div>";                                                                                                                                          
        if ($itemsInRow % 3 === 0) {                                                                                                                                    
                $itemsInRow = 0;                                                                                                                                        
                continue;                                                                                                                                               
        }                                                                                                                                                               
        $itemsInRow++;                                                                                                                                                  
}

这就是你想要实现的吗?如果正确的话,我会改进我的答案。这没有经过测试。