欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP云打印類完整示例

 更新時間:2016年10月15日 12:06:34   作者:dengwz7788  
這篇文章主要介紹了PHP云打印類,結合完整實例形式分析了php實現(xiàn)網(wǎng)絡打印數(shù)據(jù)的搜集與隊列排序整理及數(shù)據(jù)打印等功能,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了PHP云打印類。分享給大家供大家參考,具體如下:

一個項目需求要幾百臺電腦都有打印功能,本來是想用網(wǎng)絡打印機的,后來發(fā)現(xiàn)沒有網(wǎng)絡打印機,就自己動手寫一個打印類算了。

類實現(xiàn)想法是:先把要打印的數(shù)據(jù)都收集起來,在用js調(diào)用window打印函數(shù)。目前就使用于IE。

類提供打印排隊功能。(PS,說白了就是一條一條讀取數(shù)據(jù))

class Wprint{
   //收集打印代碼
   private $data = array();
   //處理打印代碼
   private $handle;
   public function __construct()
  {
    header("Content-type:text/html;charsetutf-8");
    $this->link(); //鏈接數(shù)據(jù)庫
    $this->collect($_POST["username"],$_POST["content"],$_POST["ip"]);
    $this->handle();
   }
   //鏈接數(shù)據(jù)庫
   private function link()
   {
    $link = mysql_connect('localhost', 'root', '123456');
    mysql_select_db('shen', $link);
    mysql_query('SET NAMES utf8');
   }
   //收集打印代碼
   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);//數(shù)據(jù)節(jié)點入棧
   }
   //處理打印代碼入庫
   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(); //獲取最近insert操作得到的ID
      echo "數(shù)據(jù)收集成功,正在排隊打印,排隊ID為".$id;
      $this->num($id);
     }
     else
     {
      echo "數(shù)據(jù)收集失敗,請3秒后再一次提交";
     }
    }
   }
    //檢查傳人數(shù)據(jù)是否為空
   private function check($string)
   {
    if(strlen($string) == 0 || $string == " ")
    {
     echo "數(shù)據(jù)收集失敗,打印內(nèi)容為空";
     exit;
    }else
    {
     return $string;
    }
   }
   //獲取打印排隊人數(shù)
   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 ",您前面還有".$num."個人在排隊";
   }
   //打印數(shù)據(jù)
   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 "打印處理完成";
     }else
     {
       echo $row["content"];
     }
   }
}

思想很簡單,收集數(shù)據(jù)再一個一個處理。 這樣就不僅解決了網(wǎng)絡打印的問題,還避免了網(wǎng)絡打印打印過程排隊的問題。

更多關于PHP相關內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)據(jù)結構與算法教程》、《PHP運算與運算符用法總結》、《PHP網(wǎng)絡編程技巧總結》、《PHP基本語法入門教程》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php面向?qū)ο蟪绦蛟O計入門教程》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論