PHP cloud printing complete example, php cloud example

Source: Internet
Author: User

PHP cloud printing complete example, php cloud example

This article describes the PHP cloud printing class. We will share this with you for your reference. The details are as follows:

A project requires hundreds of computers to have a print function. Originally, I wanted to use a network printer. Later I found that there was no network printer, so I wrote a print class myself.

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)

Class Wprint {// collect and print the code private $ data = array (); // process and print the code private $ handle; public function _ construct () {header ("Content-type: text/html; charsetutf-8 "); $ this-> link (); // link database $ this-> collect ($ _ POST [" username "], $ _ POST ["content"], $ _ POST ["ip"]); $ this-> handle ();} // link to the database private function link () {$ link = mysql_connect ('localhost', 'root', '000000'); mysql_select_db ('shen', $ link); mysql_query ('set NA MES 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 into 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 echo obtained by the last insert operation. 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 uploaded 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 print queue count. 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 have ". $ num. "individuals are queuing";} // 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 "<script tyle = \" text/javascript \ "> window. print (); </script> "; $ id = $ row [" id "]; $ SQL =" update print set state = 1 where id = ". $ id; mysql_query ($ SQL); echo "Print processed" ;}else {echo $ row ["content"] ;}}

The idea is simple. Collect data and process it one by one. This not only solves the problem of network printing, but also avoids the problem of queuing during network printing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.