Polls::query PHP Method

query() public method

public query ( $limit = 25, $index )
    public function query($limit = 25, $index = 0)
    {
        $sth = $this->db->query("SELECT COUNT(*) FROM polls");
        $res = $sth->fetch();
        $totalCount = $res[0];
        $sth = $this->db->prepare("SELECT * FROM polls ORDER BY added DESC LIMIT ?, ?");
        $sth->bindParam(1, $index, PDO::PARAM_INT);
        $sth->bindParam(2, $limit, PDO::PARAM_INT);
        $sth->execute();
        $polls = $sth->fetchAll(PDO::FETCH_ASSOC);
        $polls = array_map(function ($poll) {
            return $this->generatePoll($poll);
        }, $polls);
        return array($polls, $totalCount);
    }

Usage Example

Example #1
0
     break;
 case validateRoute('POST', 'faq'):
     $faq = new Faq($db, $user);
     httpResponse($faq->create($postdata));
     break;
 case validateRoute('PATCH', 'faq/\\d+'):
     $faq = new Faq($db, $user);
     httpResponse($faq->update($params[1], $postdata));
     break;
 case validateRoute('DELETE', 'faq/\\d+'):
     $faq = new Faq($db, $user);
     httpResponse($faq->delete($params[1]));
     break;
 case validateRoute('GET', 'polls'):
     $polls = new Polls($db, $user);
     httpResponse($polls->query());
     break;
 case validateRoute('GET', 'polls/latest'):
     $polls = new Polls($db, $user);
     httpResponse($polls->getLatest());
     break;
 case validateRoute('POST', 'polls/votes/\\d+'):
     $polls = new Polls($db, $user);
     httpResponse($polls->vote($params[2], (int) $postdata["choise"]));
     break;
 case validateRoute('POST', 'polls'):
     $forum = new Forum($db, $user);
     $polls = new Polls($db, $user, $forum);
     $polls->create($postdata);
     httpResponse();
     break;
All Usage Examples Of Polls::query