jQuery Print Dynamic Content using PHP MySQL Example

Today, We want to share with you jQuery Print Dynamic Content using PHP MySQL Example.In this post we will show you PHP Web Print Generating Dynamic Content, hear for Partial Print Document Tutorial HTML div Content in PHP we will give you demo and example for implement.In this post, we will learn about How to create a dynamic webpage fetching data from a database in PHP with an example.

jQuery Print Dynamic Content using PHP MySQL Example

There are the Following The simple About jQuery Print Dynamic Content using PHP MySQL Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Print Dynamic Content using JavaScript, jQuery, and PHP, so the Print DIV contents with CSS using JavaScript and jQuery for this example is following below.

Step 1 : Create Mysql Database Table

SQL creates a members table

CREATE TABLE `members` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `email` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
 `mobile` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
 `created_at` datetime NOT NULL,
 `updated_at` datetime NOT NULL,
 `status` enum('Active','Inactive') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Active',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Step 2 :Database Configuration

database_config.php

connect_error) {
    die("Connection failed: " . $db->connect_error);
}

Step 3 : Print Dynamic Content

(index.php)HTML and PHP source code

query("SELECT id, name FROM members");
?>

<!-- Dropdown to select the member -->

    Select Member
    fetch_assoc()){ ?>
    <option value="">
    


<!-- Print button -->
<button id="getMember">Print Details</button>

<!-- Hidden div to load the dynamic content -->
<div id="memberInfo"></div>

Include the External jQuery library

Step 4 : JavaScript Source code

jQuery load() method

$(document).ready(function(){
    $('#getMember').on('click',function(){
        var memberID = $('#memberSelect').val();
        $('#memberInfo').load('retriveMember.php?id='+memberID,function(){
            var printContent = document.getElementById('memberInfo');
            var memberPrint = window.open('', '', 'width=900,height=650');
            memberPrint.document.write(printContent.innerHTML);
            memberPrint.document.close();
            memberPrint.focus();
            memberPrint.print();
            memberPrint.close();
        });
    });
});

Step 5 : Load SERVER SIDE Dynamic Data (retriveMember.php)

retriveMember.php

query("SELECT * FROM members WHERE id = ".$memberID);
    
    if($query->num_rows > 0){
        $memberData = $query->fetch_assoc();
    }
}
?>

<h2>Print Dynamic Content using JavaScript, jQuery, and PHP</h2>
<!-- Render the member details -->
<div class="container">
    <h2>Member Information</h2>
    
        <p><b>Member Name:</b> </p>
        <p><b>Member Email:</b> </p>
        <p><b>Mobile:</b> </p>
        <p><b>Created:</b> </p>
        <p><b>Status:</b> </p>
    
        <p>Member not found...</p>
    
</div>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about jQuery Print Dynamic Content using PHP MySQL Example.
I would like to have feedback on my Pakainfo.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.