0

let' say i have 20 results in the sql query. if am gonna use the limit in the yii active record, I'll obviously get the first four from the result, but what if i wanna get the 2nd four and then 3rd four in the same query result ? how to query that via sql ?

e.g

        $criteria2 = new CDbCriteria();
        $criteria2->select = 'USERID, ADID ,ADTYPE, ADTITLE, ADDESC, PAGEVIEW, DISPPUBLISHDATE';
        $criteria2->addCondition("STATUS = 1");
        $criteria2->order = '"t".PAGEVIEW DESC,"t".PUBLISHDATE DESC';
        $criteria2->limit = 4;
        $criteria2->with = array('subcat','adimages');
        $result = $this->findAll($criteria2);
        return $result;
sasori
  • 5,249
  • 16
  • 86
  • 138

1 Answers1

1

Sorry :)

See here, how to paginate with Oracle (Are you use 11g?) Alternatives to LIMIT and OFFSET for paging in Oracle

Well and in Yii just set offset, OCIConnector will set rownum automaticly for sql

    $criteria2 = new CDbCriteria();
    $criteria2->select = 'USERID, ADID ,ADTYPE, ADTITLE, ADDESC, PAGEVIEW, DISPPUBLISHDATE';
    $criteria2->addCondition("STATUS = 1");
    $criteria2->order = '"t".PAGEVIEW DESC,"t".PUBLISHDATE DESC';
    $criteria2->limit = 4;
    $criteria2->offset = 0; //4, 8 - COciCommandBuiled applyLimit use it
    $criteria2->with = array('subcat','adimages');
    $result = $this->findAll($criteria2);
    return $result;
Community
  • 1
  • 1
Sergey
  • 5,208
  • 25
  • 36
  • what's that "COciCommandBuiled applyLimit use it" ?, do i need to tweak the yii framework class that has something to do with the schema ? – sasori Nov 06 '12 at 05:47
  • @sasori, you do not need make any tweaks for get next 4's element - just set offset = 4; (3rd - offset = 8 etc) – Sergey Nov 06 '12 at 08:56