JohnPaulDesign
11/25/2016 - 2:25 PM

show multiple rows of dynamic data from a table and repeat each row in html block

show multiple rows of dynamic data from a table and repeat each row in html block

<?php
    //select all data from the 'posts' table
    $query = "SELECT * FROM posts";
    $select_all_posts = mysqli_query($connection, $query);
    
    //start a while loop 
    while($row = mysqli_fetch_assoc($select_all_posts)) {
        
        //select each required column name and assign to variable
        $post_title = $row['post_title'];
        $post_author = $row['post_author'];
        $post_date = $row['post_date'];
        $post_content = $row['post_content'];
        
//close the php tag before ending the while loop
?>


<-- because the while loop has not been ended, the following code block will be repeated like rows in a table -->

<h2><?php echo $post_title; ?></h2>
<p class="lead"><a href="index.php"><?php echo $post_author; ?></a></p>
<p>Posted on <?php echo $post_date; ?></p>
<p><?php echo $post_content; ?></p>
<hr>

<?php } //re-open php and then close the while loop ?>