dimanche 25 octobre 2020

Combine php (if and while) with html

What is the right way to combine php with html? I always echo the html but I'm not sure if this is the right way to do it.

Example:

<div class="row mt-4">
        <?php
            if ($queryResult > 0) {
                while ($row = mysqli_fetch_assoc($result)) {
                    echo '
                    <div class="col-md-3 mb-3">
                        <a class="link-unstyled" href="article.php?title='. $row["a_title"] .'&date='. $row["a_date"] .'">
                            <div class="card shadow-box">
                                <div class="card-header">
                                    '. $row["a_title"] .'
                                </div>
                                <div class="card-body" style="height: 150px;overflow: auto; scrollbar-width: thin;">
                                    <h4 class="card-title">'. $row["a_title"] .'</h4>
                                    <p class="card-text">
                                    '. $row["a_text"] .'<br>
                                    </p>
                                </div>
                                <div class="card-footer text-muted">
                                '. $row["a_author"] .'<br>
                                '. $row["a_date"] .'
                                </div>
                            </div>
                        </a>
                    </div>            
                    ';
                }
            } else {
                echo "<p>There are no results matching your search!<br> go back to the <a href='index.php'>homepage</a><p>";
            }
        ?>
    </div>

Aucun commentaire:

Enregistrer un commentaire