public function indexAction() { $p = $_REQUEST; $pKey = empty($p['key']) ? '' : Tool_Fnc::safe_string($p['key']); $tMO = new ArticleModel(); if (!empty($pKey)) { $tWhere = 'description like \'%' . $pKey . '%\' or title like \'%' . $pKey . '%\''; $pCount = $tMO->field('count(*) c')->where($tWhere)->fRow(); } else { $pCount = $tMO->field('count(*) c')->fRow(); } $pNum = 10; if (!empty($pCount['c'])) { $tPG = new Tool_Page($pCount['c'], $pNum); if (!empty($pKey)) { $tDatas = $tMO->field('*')->where($tWhere)->limit($tPG->limit())->fList(); } else { $tDatas = $tMO->field('*')->limit($tPG->limit())->fList(); } $this->assign('tShow', $tPG->show()); } else { if (!empty($pKey)) { $tDatas = $tMO->field('*')->where($tWhere)->fList(); } else { $tDatas = $tMO->field('*')->fList(); } $this->assign('tShow', ''); } $this->assign('tDatas', $tDatas); }
public function indexAction() { $p = $_REQUEST; $pKey = empty($p['key']) ? '' : Tool_Fnc::safe_string($p['key']); $tMO = new FoodunitsModel(); $tFM = new FoodModel(); if (!empty($pKey)) { $sql = " select count(*) c from food_units a left join food b on a.fid = b.id where b.title like \"%" . $pKey . "%\""; } else { $sql = " select count(*) c from food_units a left join food b on a.fid = b.id "; } $pCount = $tMO->query($sql); $pNum = 10; if (!empty($pCount[0]['c'])) { $tPG = new Tool_Page($pCount[0]['c'], $pNum); if (!empty($pKey)) { $sql = " select a.*,b.title from food_units a left join food b on a.fid = b.id where b.title like \"%" . $pKey . '%" limit ' . $tPG->limit(); } else { $sql = " select a.*,b.title from food_units a left join food b on a.fid = b.id limit " . $tPG->limit(); } $tDatas = $tMO->query($sql); $this->assign('tShow', $tPG->show()); } else { if (!empty($pKey)) { $sql = " select a.*,b.title from food_units a left join food b on a.fid = b.id where b.title like \"%" . $pKey . '%" '; } else { $sql = " select a.*,b.title from food_units a left join food b on a.fid = b.id "; } $tDatas = $tMO->query($sql); $this->assign('tShow', ''); } $this->assign('tDatas', $tDatas); }
public function indexAction() { $p = $_REQUEST; $pKey = empty($p['key']) ? '' : Tool_Fnc::safe_string($p['key']); $tAM = new AdminModel(); if (!empty($pKey)) { $tWhere = "name like '%{$pKey}%'"; $pCount = $tAM->field('count(*) c')->where($tWhere)->fRow(); } else { $pCount = $tAM->field('count(*) c')->fRow(); } $pNum = 10; if (!empty($pCount['c'])) { $tPG = new Tool_Page($pCount['c'], $pNum); if (!empty($pKey)) { $tDatas = $tAM->field('*')->where($tWhere)->limit($tPG->limit())->fList(); } else { $tDatas = $tAM->field('*')->limit($tPG->limit())->fList(); } $this->assign('tShow', $tPG->show()); } else { if (!empty($pKey)) { $tDatas = $tAM->field('*')->where($tWhere)->fList(); } else { $tDatas = $tAM->field('*')->fList(); } $this->assign('tShow', ''); } $this->assign('tDatas', $tDatas); }
public function indexAction() { $p = $_REQUEST; $pKey = empty($p['key']) ? '' : Tool_Fnc::safe_string($p['key']); $tUMO = new UserModel(); $tWhere = ' 1 = 1 '; if (!empty($pKey)) { $tWhere .= ' and nickname like \'%' . $pKey . '%\''; } $tCount = $tUMO->field('count(*) c')->where($tWhere)->fRow(); $tCnt = empty($tCount['c']) ? 0 : $tCount['c']; $pNum = 10; $tPG = new Tool_Page($tCnt, $pNum); $tDatas = array(); if (!empty($tCnt)) { $tDatas = $tUMO->field('*')->where($tWhere)->order('id asc')->limit($tPG->limit())->fList(); } $this->assign('tShow', $tPG->show()); $this->assign('tDatas', $tDatas); }
public function indexAction() { $p = $_REQUEST; $pKey = empty($p['key']) ? '' : Tool_Fnc::safe_string($p['key']); $pDaydate = empty($p['day_date']) ? '' : Tool_Fnc::safe_string($p['day_date']); $tMO = new DailyrecipesModel(); $tWhere = array(); if (!empty($pDaydate)) { $pDaydate = date('Y-m-d', strtotime($pDaydate)); $tWhere[] = ' day_date = \'' . $pDaydate . '\' '; } if (!empty($pKey)) { $tWhere[] = ' tag like \'%' . $pKey . '%\' or title like "%' . $pKey . '%"'; } if (!empty($tWhere)) { $tWhere = implode(' and ', $tWhere); $pCount = $tMO->field('count(*) c')->where($tWhere)->fRow(); } else { $pCount = $tMO->field('count(*) c')->fRow(); } $pNum = 10; if (!empty($pCount['c'])) { $tPG = new Tool_Page($pCount['c'], $pNum); if (!empty($tWhere)) { $tDatas = $tMO->field('*')->where($tWhere)->limit($tPG->limit())->fList(); } else { $tDatas = $tMO->field('*')->limit($tPG->limit())->fList(); } $this->assign('tShow', $tPG->show()); } else { if (!empty($tWhere)) { $tDatas = $tMO->field('*')->where($tWhere)->fList(); } else { $tDatas = $tMO->field('*')->fList(); } $this->assign('tShow', ''); } $this->assign('tDatas', $tDatas); }
/** * 获得模型的列表 * @param String $pTable 数据表名 * @param String $pConn 条件 L=查询条数 &OB=排序 &cid=分类ID &字段=值 * @return array */ protected function _list($pTable, $pConn = '', $pPage = '') { # 实例化模型 $this->_table2obj($pTable); # 自动搜索 if (!empty($_GET['field']) && !empty($_GET['kw'])) { empty($pConn) || ($pConn .= '&'); # like 搜索 if (false === strpos($_GET['field'], '*')) { $pConn .= $_GET['field'] . '=' . $_GET['kw']; } else { $pConn .= str_replace('*', '', $_GET['field']) . '=LIKE *' . $_GET['kw'] . '*'; } } # 查询条数 parse_str($pConn, $tConn); if (isset($tConn['L'])) { $tLimit = $tConn['L']; unset($tConn['L']); } else { $tLimit = 10; } # 排序 if (isset($tConn['OB'])) { $tOB = $tConn['OB']; unset($tConn['OB']); } else { $tOB = ''; } # Where 条件 if (!empty($pTable->options['where'])) { $tWhere = $pTable->options['where']; } else { $tWhere = array(); foreach ($tConn as $k1 => $v1) { if (0 === strpos($k1, 'SQL')) { # SQL: SQL=abc $tWhere[] = "{$v1}"; } elseif (0 === strpos($v1, 'IN')) { # IN: field=IN(1,2,3) 将转换为 field IN(1,2,3) $tWhere[] = "{$k1} {$v1}"; } elseif (0 === strpos($v1, 'LIKE')) { # LIKE:field=LIKE abc* 将转换为 field LIKE 'abc%' $v1 = str_replace('*', '%', substr($v1, 5)); $tWhere[] = "{$k1} LIKE '{$v1}'"; } else { $tWhere[] = "{$k1}='{$v1}'"; } } if ($tWhere = join(' AND ', $tWhere)) { $pTable->where($tWhere); } } # 不带分页 if (false === $pPage) { return $this->_view->assign('datas', $pTable->limit($tLimit)->order($tOB)->fList()); } # 需要分页 $tField = isset($pTable->options['field']) ? $pTable->options['field'] : '*'; if (!($tCnt = $pTable->count())) { return $this->_view->assign(array('datas' => array(), 'pageinfo' => '')); } $tPage = new Tool_Page($tCnt, $tLimit); $tWhere && $pTable->where($tWhere); $this->_view->assign('datas', $pTable->field($tField)->limit($tPage->limit())->order($tOB)->fList()); $this->_view->assign('pageinfo', $tPage->show($pPage)); }