How to generate a html page dynamically using PHP?

How to generate a html page dynamically using PHP – Building a Dynamic Web App using PHP & MySQL – A dynamic website is a site that contains dynamic pages such as templates, contents, scripts etc.

How to generate a html page dynamically using PHP

First of all You need to install MySQL & PHP, Create databases, users, and tables in MySQL and create the database connection in PHP and then Start creating folder structure.

Creating Dynamic Web Sites with PHP and MySQL

Creating Dynamic Pages with php and MySQL

main.php

<?php
require_once "config.php";

$sql_query = $conn->query("SELECT * FROM members ORDER BY memId");

if ($sql_query->num_rows > 0) {
// output data of each row
while($row = $sql_query->fetch_assoc()) {

echo "<tr><td><a href='index.php?member_id=".$row["member_id"]."&memId=".$row["memId"]."'>" .$row["members"]. "</a></td></tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>

index.php

<script type="text/javascript">

        var start = 0;
        var limit = 20;
        var finalItemLim = false;
        var midnew = <?php echo $_POST("memId"); ?>

        $(window).scroll(function () {
            if ($(window).scrollTop() == $(document).height() - $(window).height() )

                getData();
        });

        $(document).ready(function () {
           getData();
        });

        function getData() {
            if (finalItemLim)
                return;

            $.ajax({
               url: 'data.php',
               method: 'POST',
                dataType: 'text',
               data: {
                   getData: 1,
                   start: start,
                   limit: limit,
                   midnew: midnew,
               },
               success: function(response) {
                    if (response == "finalItemLim")
                        finalItemLim = true;
                    else {
                        start += limit;
                        $(".results").append(response);
                    }
                }
            });
        }
    </script>

Don’t Miss : Create Dynamic Web Pages Using PHP-MYSQL

data.php

<?php

if (isset($_POST['getData']) ) {

    $conn = new mysqli('localhost', 'root', '[email protected]', 'pakainfo_v41');

    $midnew = $conn->real_escape_string($_POST['midnew']);
    $start = $conn->real_escape_string($_POST['start']);
    $limit = $conn->real_escape_string($_POST['limit']);

    $sql = $conn->query("SELECT * FROM pakainfo_v1 WHERE memId='$midnew' ORDER BY kayit_no DESC LIMIT $start, $limit");
    if ($sql->num_rows > 0) {
        $response = "";

        while($row_result = $sql->fetch_array()) {
            $response .= '


<tr>
           <td>ICD#'.$row_result['kayit_no'].'</td>
           <td>'.$row_result['donemi'].'</td>
           <td><img src="medias/'.$row_result['kay_board'].'" border="2" width="300px" /></td>
           <td>'.$row_result['demo_info'].'</td>
           <td>'.$row_result['kininfo'].'</td>
           <td>'.$row_result['level_in'].'</td>
           <td>'.$row_result['news_li'].'</td>
           <td>'.$row_result['dag'].'</td>
           <td>'.$row_result['curnt_s'].'</td>
           <td>'.$row_result['reference'].'</td>


            </tr>
            ';
        }

        exit($response);
    } else
        exit('finalItemLim');
}

?>

I hope you get an idea about How to generate a html page dynamically using PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.