-2

I want to print mysql data which is retrieve from mysql via printer ...

Please donot answer it CTRL + P ...

i want a button which can send all the retrieve data of mysql to printer ... I should be able to print the data via printer ...

Thanks

Chandan Rai
  • 9,879
  • 2
  • 20
  • 28
Bilal Shah
  • 7
  • 1
  • 3

1 Answers1

3

This is already answered. Use the solution given in following link:

How to print a page in PHP to print using printer same as window.print() works

The variable $htmlvariable in this link should contain the data fetched from Mysql(as in your case).

like

$html="<table><tr><td>ID</td><td>Name</td><td>Description</td></tr>";

mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name, desc FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$html.="<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
}

$html.="</table>";
Community
  • 1
  • 1
Techroshni
  • 541
  • 2
  • 11
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jan 24 '17 at 12:29
  • lol..Thanks I work with PDO only and I used mysqli long back :-) ..The purpose was to give the idea and not the exact code as the question seems very basic..Good catch though :-) – Techroshni Jan 25 '17 at 07:15