PHP Cloud Printing class complete sample _php tips

Source: Internet
Author: User

This example describes the PHP cloud printing class. Share to everyone for your reference, specific as follows:

A project needs hundreds of computers have a printing function, is intended to use a network printer, and later found that there is no network printer, they write a print class.

Class implementation idea is: first to print the data are collected, in the use of JS call window printing function. Currently used for IE.

class provides print queuing functionality. (PS, plainly is a piece of reading data)

Class wprint{//Collect print code Private $DATA = Array ();
   Process printing code private $handle;
    Public Function __construct () {Header ("content-type:text/html;charsetutf-8"); $this->link ();
    Linked database $this->collect ($_post["username"],$_post["content"],$_post["IP"));
   $this->handle ();
    //Link Database private Function link () {$link = mysql_connect (' localhost ', ' root ', ' 123456 ');
    mysql_select_db (' Shen ', $link);
   mysql_query (' SET NAMES utf8 ');
     //Collect Print 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 print code warehousing private Function handle () {foreach ($this->data As $value) {$sql = INSERT into print (username,content,ip,state,priority) values (' {$value [username]} ', ' {$value [] con Tent "]} ', ' {$value [IP]} ', ' {$value["state"} ', ' {$value [' priority ']} ');
     $query = mysql_query ($sql);
      if ($query) {$id = mysql_insert_id ();//Get ID echo of recent insert operation successfully, queued for print, queue ID. $id;
     $this->num ($id);
     ' Else {echo ' data collection failed, please submit again after 3 seconds '; 
     Check to see if the descendant data is empty private function check ($string) {if (strlen ($string) = 0 | | $string = = "") {
     echo "Data collection failed with blank print";
    Exit
    }else {return $string; Get the number of print queues private function num ($id) {$sql = "SELECT id from print where state=0 and id<". $id. "or
    Der by id ASC ";
    $query = mysql_query ($sql);
    $num = mysql_num_rows ($query); echo ", you also have". $num. "
   individuals 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 <script tyle=\ "text/javascript\" &Gt
        Window.print ();
      </script> ";
      $id = $row ["id"];
      $sql = "Update print set state=1 where id=". $id;
      mysql_query ($sql);
     echo "Print processing complete";
     }else {echo $row ["content"];

 }
   }
}

The idea is simple, collect the data one by one and deal with it. This not only solves the problem of network printing, but also avoids the problem of queueing in the network print printing process.

For more information about PHP interested readers can view the site topics: "PHP Data structure and algorithm tutorial", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"

I hope this article will help you with the PHP program design.

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.