Pagination in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Pagination in php

    I want to put pagination in my search result. my code is working but got an error saying:Non-static method Pager::factory( ) should not be called statically in...
    This is my code.

    Code:
    require_once 'Pager/Pager.php';
    $sqlQuery = "select * from vehicles";
    $result = mysql_query($sqlQuery);
    $totalRows = mysql_num_rows($result);
     
    $pager_options = array(
    'mode'       => 'Sliding',
    'perPage'    => 20,
    'delta'      => 4,
    'totalItems' => $totalRows,
    );
    
    $pager =Pager::factory($pager_options);
    
    echo $pager->links;
    list($from, $to) = $pager->getOffsetByPageId();
    
    $from = $from - 1;
     
    /* The number of rows to get per query */
    $perPage = $pager_options['perPage'];
     
    $result = mysql_query("SELECT * FROM vehicles LIMIT $from , $perPage");
     
    
    echo "<table width=100% align=center>";
    						echo "&nbsp;&nbsp;<tr height=20 bgcolor=#C0C0C0><td align=center>Vehicle Id</td><td align=center>Vehicle Make</td><td align=center>Vehicle Model</td><td>SELECT</td></tr>";
    		
    						while($row = mysql_fetch_array($result))
    						{
    							foreach( $row AS $key => $val ){
    							$$key = stripslashes( $val );
    							}
    			
    							echo "<tr class=normalText>";
    						 	echo "<td> $vehicleId</td>";
    							echo "<td> $vehicleMake</td>";
    							echo "<td> $vehicleModel</td>";
    
    							echo  "<td><a href='javascript:void(0);' onclick=\"LookupVehicle('$vehicleType','$vehicleMake'); return false;\">Select</a></td>";
    									echo "</tr>";
    							}
    							echo "</table>";
    This is the error line.
    Code:
    $pager =Pager::factory($pager_options);
    Please help me..
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the error is right, if you didn’t declare the method static in the class definition, you should call it like an object method (i.e. $obj->method()). whether you should do this or declare the method static depends on the method implementation, though.

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      Thanx Dormilich. I solved it. But Now I'm having another problem. When I click page no 2; web banner and all other page options not displayed and only disply the pagination part. How can I solve this problem. I have searched many days and found this solution. Please help me. Now I'm really stuck. Please help me to solve this or please tell me about another working pagination tutorial..

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        When I click page no 2; web banner and all other page options not displayed and only disply the pagination part
        sounds like the links used are incorrect.

        please tell me about another working pagination tutorial.
        I don’t know any. I already have my own pagination system. Google certainly knows some more.

        Comment

        Working...