<?php class classExport{ public $dbname; public $tbname; public $vname; public $searchtext = ""; public $datafield =""; // ID,รข,b,c public $i = 0 ; // cai biem dem vong for vay thoi private $mysql; public function __construct() { global $mysql, $CurrentAccount; $this->mysql = $mysql; $this->CurrentAccount = $CurrentAccount; $this->mysql->select_db($this->dbname); } // public function getStatusTable(){ $sql = 'SHOW TABLE STATUS FROM `' . $this->dbname . '` WHERE `Name` = "' . $this->tbname . '" AND ENGINE IS NOT NULL;'; $statusInfo = $this->mysql->qfo($sql); return $statusInfo; } public function getSplitFile(){ $statusInfo= $this->getStatusTable(); $size = $statusInfo->Data_length; $totalRows = $statusInfo->Rows; $size = $size / 1024; //->>> convert byte -> KB $maxsize = 3072; // -> 3MB $totalfile = ceil($size / $maxsize); //-> tong so file $recordperFile = ceil($totalRows / $totalfile); // so record trong 1 file $cname = $this->mysql->get_table_field_names_array($this->vname); //edit gettable_fieldname $fieldlist = $this->mysql->get_attr_table($this->vname); $fields = "`" . implode("`, `", $fieldlist['field']) . "`"; // ID,aa,bb,cc ... $spitFile = array(); $spitFile['totalfile'] = $totalfile; $spitFile['recordperFile'] = $recordperFile; $spitFile['cname'] = $cname; $spitFile['fields'] = $fields; return $spitFile; } public function getSQLString(){ $spitfileInfo = $this->getSplitFile(); $recordperFile = $spitfileInfo['recordperFile']; $totalfile = $spitfileInfo['totalfile']; $cname = $spitfileInfo['cname']; $fields = $spitfileInfo['fields']; $start = ($this->i - 1) * $recordperFile; if ($this->searchtext!="") { $searchtext = $this->searchtext; $datafield = $this->datafield; if ($datafield != 'AllColumns') $sqlquery = 'SELECT ' . $fields . ' FROM `' . $this->vname . '` WHERE `' . $datafield . '` LIKE "%' . $searchtext . '%"'; else { $sqlquery = "select $fields from `" . $this->vname . "` where "; foreach ($cname as $fname) { $sqlquery .= "`".$fname . "` like('%" . $searchtext . "%') or "; } $sqlquery = rtrim($sqlquery, 'or '); // $sqlquery .= ' limit '.$start.','.$recordperFile; } } else { $sqlquery = 'select ' . $fields . ' from `' . $this->dbname . '`.`' . $this->vname . '` limit ' . $start . ',' . $recordperFile; } return $sqlquery; } } ?>