优化了调用逻辑,减少数据库查询次数

This commit is contained in:
Li Jianxuan 2011-10-13 09:09:42 +00:00
parent 646beea985
commit bd7392f5d1
1 changed files with 18 additions and 6 deletions

View File

@ -4,6 +4,7 @@ class EmailText{
var $tmpid; var $tmpid;
var $db; var $db;
var $data; var $data;
var $tmpinfo;
function __construct() function __construct()
{ {
@ -13,19 +14,30 @@ class EmailText{
} }
} }
public function getinfo(){
if(is_numeric($this->tmpid))
$sql = "select * from emailtext where id='".$this->tmpid."'";
else
$sql = "select * from emailtext where template='".$this->tmpid."'";
$rs = $this->db->query($sql);
$this->tmpinfo = $rs->fetch();
}
public function loadtmp(){ public function loadtmp(){
if(empty($this->tmpid)) if(empty($this->tmpid))
{ {
return false; return false;
}else{ }else{
if(is_numeric($this->tmpid))
$sql = "select id,body from emailtext where id='".$this->tmpid."'";
else
$sql = "select id,body from emailtext where template='".$this->tmpid."'";
$rs = $this->db->query($sql);
$c = $rs->fetch(); $this->getinfo();
$c = $this->tmpinfo;
if(!empty($c['id'])) if(!empty($c['id']))
{ {
if(count($this->data)==0) if(count($this->data)==0)