How to print html table in php

I have a table in a PHP page. It is a invoice. So I want to print it after adding items to it, and I had already done the coding part and all the things are working properly.

Now I just want to print that invoice table to a paper by pressing a button. I searched on Google but no clue is found to do that.

Can any one help me?

This is my table on right hand side. It is populated by the form in left hand side so I just want to print that right hand side table:

How to print html table in php

How to print html table in php

asked Jul 22, 2012 at 4:40

How to print html table in php

3

Try this one:

Add an attribute id to your table your_content

Place an anchor tag :

   Print 

And add script:

This script will initially show print preview of the content that is inside your table.

 

Print 

​​​​​​

You can see the demo here: http://jsfiddle.net/Pxqtb/

answered Jul 22, 2012 at 6:11

pat34515pat34515

1,93912 silver badges13 bronze badges

0

i used this code and it solved my problem. thank you all for helping me.....

function printlayout() {
     var data = '';           
       var DocumentContainer = document.getElementById('printlayout');
        //data += $('printlayoutable').html();
        //data += '';
var WindowObject = window.open('', "TrackHistoryData",
"width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
WindowObject.document.writeln(DocumentContainer.innerHTML);
//WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();

answered Jul 22, 2012 at 7:03

How to print html table in php

YasithaYasitha

9012 gold badges17 silver badges41 bronze badges

You have a few options. (1) If you create a new HTML page with just the invoice, the user can print that page using the browser's print capacity. (2) Alternatively, you can allow the user to download an invoice document which you create and print that. (3) You can use the JavaScript command window.print(); in conjunction with #1. Have a look at this.

answered Jul 22, 2012 at 4:48

NickNick

5,90711 gold badges52 silver badges77 bronze badges

How to print table in HTML using PHP?

click(function(){ var data = ''; data += '
'; data += $('#your_content'). html(); data += '
'; myWindow=window. open('','','width=200,height=100'); myWindow.

How to display table in PHP?

Steps to Display Data From MySQL Database with PHP.
Connect PHP to MySQL Database..
Insert Data Into PHPMyAdmin Table..
Fetch Data From MySQL Table..
Display Data in HTML Table..
Test Yourself to insert data..
Display Data using MySQLi Procedure..
Display Data Using MySQLi Object-Oriented..

How do you print a table in HTML?

The HTML Table will be printed with a Print Preview using JavaScript. The following HTML Markup consists of an HTML DIV inside which there is an HTML Table and an HTML Button. The Button has been assigned a JavaScript OnClick event handler which makes call to a JavaScript function named PrintTable.

How fetch data from database in PHP and display HTML table?

Use the following steps for fetch/retrieve data from database in php and display in html table:.
Step 1 – Start Apache Web Server..
Step 2 – Create PHP Project..
Step 3 – Execute SQL query to Create Table..
Step 4 – Create phpmyadmin MySQL Database Connection File..
Step 5 – Create Fetch Data PHP File From Database..