The printing implementation principle is very simple: when the user clicks print, the data is saved to the database, and then js calls the printer to print the data. If the printing is finished, the record is deleted and another print is executed, the Code is as follows. The printing implementation principle is very simple: when the user clicks print, the data is saved to the database, and then js calls the printer to print the data. If the printing is finished, the record is deleted and another print is executed, the Code is as follows.
Script ec (2); script
Class implementation idea: first collect all the data to be printed and call the window printing function in js. It is currently used in IE.
Class provides the print queuing function. (PS. To put it bluntly, reading data one by one)
| The Code is as follows: |
|
Class Wprint { // Collect and print the code Private $ data = array (); // Process printed code Private $ handle; Public function _ construct () { Header ("Content-type: text/html; charsetutf-8 "); $ This-> link (); // link to the database $ This-> collect ($ _ POST ["username"], $ _ POST ["content"], $ _ POST ["ip"]); $ This-> handle (); } // Link to the database Private function link () { $ Link = mysql_connect ('localhost', 'root', '123 '); Mysql_select_db ('shen', $ link ); Mysql_query ('set NAMES utf8 '); } // Collect and print the code Private function collect ($ username, $ content, $ ip) { $ Code ["username"] = $ username; $ Code ["content"] = $ this-> check ($ content ); $ Code ["ip"] = $ ip; $ Code ["state"] = 0; $ Code ["priority"] = 0; Array_push ($ this-> data, $ code); // data node entry Stack } // Process and print the code into the database Private function handle () { Foreach ($ this-> data as $ value) { $ SQL = "insert into print (username, content, ip, state, priority) Values ('{$ value ["username"]}', '{$ value ["content"]}', '{$ Value ["ip"]}', '{$ value ["state"]}', '{$ value ["priority"]}') "; $ Query = mysql_query ($ SQL ); If ($ query) { $ Id = mysql_insert_id (); // obtain the ID of the last insert operation Echo "the data is collected successfully, and is being queued for printing. The queue ID is". $ id; $ This-> num ($ id ); } Else { Echo "Data Collection failed. Please submit again 3 seconds later "; } } } // Check whether the transmitter data is empty Private function check ($ string) { If (strlen ($ string) = 0 | $ string = "") { Echo "Data Collection failed, the printed content is blank "; Exit; } Else { Return $ string; } } // Obtain the number of printed queues Private function num ($ id) { $ SQL = "select id from print where state = 0 and id <". $ id. "order by id asc "; $ Query = mysql_query ($ SQL ); $ Num = mysql_num_rows ($ query ); Echo ", you also have". $ num. "waiting in line "; } // Print data Public function Yprint () { $ SQL = "select id, content from print where state = 0 order by id asc limit 1 "; $ Query = mysql_query ($ SQL ); $ Row = mysql_fetch_array ($ query ); If (! Empty ($ row ["content"]) { Echo" |