public function myquestionAction() { $page = $this->getRequest()->getParam('page'); $account = $_COOKIE["account"]; $usertable = new UserModel(); $db1 = $usertable->getAdapter(); $questiontable = new QuestionModel(); $db2 = $questiontable->getAdapter(); //查找当前用户ID $result = $usertable->fetchRow($db1->quoteInto('email = ?', $account))->toArray(); $uid = $result['id']; //查找用户question // $questions = $questiontable-> fetchRow($db2->quoteInto('userid = ?', $uid)) ->toArray(); $num = $db2->query('SELECT COUNT(*) as num FROM question,User WHERE question.userid = User.id and User.id =? order by time desc', $uid)->fetchAll()[0][num]; //$num=count($questions); $pages = ceil($num / 3); if ($page == "") { $page = 0; } //确定页面显示的规范 处理分页的逻辑 if ($page < 3) { if ($pages > 3) { $set = array(1, 2, 3, 4); } else { $set = array(); for ($i = 1; $i <= $pages; $i++) { $set[] = $i; } } } else { if ($page >= 3) { if ($page + 3 <= $pages) { $set = array($page, $page + 1, $page + 2, $page + 3); } else { $set = array(); for ($i = $page; $i <= $pages; $i++) { $set[] = $i; } } } } $where = $db2->quoteInto('userid=?', $uid); $order = 'begin desc'; $count = 3; $offset = $page * 3; $questions = $questiontable->fetchAll($where, $order, $count, $offset)->toArray(); $this->view->results = $questions; $this->view->user = $result; $this->view->page = $page; $this->view->count = $set; }