1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP/ORACLE Pagination

Discussion in 'PHP' started by jigen, Jun 15, 2006.

  1. #1
    I have been searching and googling for 3 days now, searching for paginating an oracle with php and still no luck.
    I joined this forum in the hope that some nice people here would point me to a site or a php script for paginating oracle in php.

    thanks and more power
     
    jigen, Jun 15, 2006 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    sarahk, Jun 15, 2006 IP
  3. jigen

    jigen Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the immediate reply but still no can do...
    I have seen a code like:
    set_time_limit(0);
    if ($c=OCILogon("login", "password", "database")) {
    //echo "Successfully connected to Oracle.\n";

    } else {
    $err = OCIError();
    echo "Oracle Connect Error " . $err[text];
    }

    $SQL="Select * from table";
    $parsedS = ociparse($c, $SQL);
    OCISetPrefetch($parsedS,20);
    ociexecute($parsedS,OCI_DEFAULT);
    $nrowsS = ocifetchstatement($parsedS, $resultsS);



    $i=0;
    $j=0;
    echo "<table>\n\n";
    while( OCIFetchInto($parsedS,&$result_array,OCI_ASSOC) ) {



    if ($i>=$offset) {
    if ($j <$limit) {
    for ($k=0; $k<=count($result_array); $k++) {
    echo $result_array[$k]." ";
    }
    echo "
    ";
    $j++;
    }
    }
    $i++;
    }
    echo "
    ";

    /*
    The results have been displayed for the current page. Time to give the
    visitor a way to hit the other pages! On with the NEXT/PREV links!
    */

    // Calculate total number of pages in result
    $pages = intval($total_rows[0]/$limit);

    // $pages now contains total number of pages needed
    // unless there is a remainder from division
    if ($total_rows[0]%$limit) {
    // has remainder so add one page
    $pages++;
    }

    // Don't display PREV link if on first page
    if ($offset!=0) {
    $prevoffset=$offset-$limit;
    echo "<a href=\"$PHP_SELF?offset=$prevoffset\"><< PREV</a> &nbsp; \n";
    }

    // Now loop through the pages to create numbered links
    // ex. 1 2 3 4 5 NEXT >>
    for ($i=1;$i<=$pages;$i++) {
    // Check if on current page
    if (($offset/$limit) == ($i-1)) {
    // $i is equal to current page, so don't display a link
    echo "$i &nbsp; ";
    } else {
    // $i is NOT the current page, so display a link to page $i
    $newoffset=$limit*($i-1);
    echo "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";
    }
    }

    // Check to see if current page is last page
    if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
    // Not on the last page yet, so display a NEXT Link
    $newoffset=$offset+$limit;
    echo "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT >></a><p>\n";
    }

    /*
    We're all done with Oracle, so free the last statement identifier and logoff
    */

    $begin =($offset+1);
    $end = ($begin+($limit-1));
    if ($end > $total_rows[0]) {
    $end = $total_rows[0];
    }

    echo "There are <b>$total_rows[0]</b> results.<br>\n";
    echo "Now showing results <b>$begin</b> to <b>$end</b>.<br><br>\n";

    After executing it, the result is:

    Warning: ocifetchinto(): OCIFetchInto: ORA-01002: fetch out of sequence

    and I can't see anything wrong with the code above.

    anybody?
    thanks again
     
    jigen, Jun 15, 2006 IP