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)
 
 
  
   
   | The code is as follows | Copy Code | 
 
   
   | Class wprint{ Collect Print Code
 Private $data = Array ();
 Working with print 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 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
 }
 Handling Print Code Warehousing
 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 (); Gets the ID obtained by the recent insert operation
 echo "Data collection is successful, is queued for printing, queue ID is". $id;
 $this->num ($id);
 }
 Else
 {
 echo "Data collection failed, please submit again after 3 seconds";
 }
 }
 }
 Check if 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 Number of print 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. " 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\ ">
 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.