*FIXED* Pagination (if you need pagination script here it is

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

*FIXED* Pagination (if you need pagination script here it is

Post by mikegotnaild »

I got this tutorial from here http://www.phpnoise.com/tutorials/9/1

*EDIT-FIXED!* Pepple having trouble with pagination could just copy this and place in their own values. ( i am not taking credit for this script though) Im only taking credit for tihs part:

Code: Select all

$num=mysql_numrows($result);
	 $lo=0;
     while ($lo < $num) {
	 $SomeVariable1=mysql_result($result,$lo,"SomeField1");
     $SomeVariable2=mysql_result($result,$lo,"SomeField2");
	 
	 echo "<b>$SomeVariable1</b><br><br>$SomeVariable2<br><br>";
	 
	 ++$lo;
Just fill in ur own values

Code: Select all

<?php  
   class Pager  
   {  
       function getPagerData($numHits, $limit, $page)  
       {  
           $numHits  = (int) $numHits;  
           $limit    = max((int) $limit, 1);  
           $page     = (int) $page;  
           $numPages = ceil($numHits / $limit);  

           $page = max($page, 1);  
           $page = min($page, $numPages);  

           $offset = ($page - 1) * $limit;  

           $ret = new stdClass;  

           $ret->offset   = $offset;  
           $ret->limit    = $limit;  
           $ret->numPages = $numPages;  
           $ret->page     = $page;  

           return $ret;  
       }  
   }  
?>
<?php  
    // get the pager input values 
    $page = $_GET['page'];  
    $limit = 10;  // Change to number of rows you want displayed in each page.
    $result = mysql_query("select count(*) from YourTable");  // Change YourTable to the table in MySQL you want to get your data from.
    $total = mysql_result($result, 0, 0);  

    // work out the pager values 
    $pager  = Pager::getPagerData($total, $limit, $page);  
    $offset = $pager->offset;  
    $limit  = $pager->limit;  
    $page   = $pager->page;  

    // use pager values to fetch data 
    $query = "select * from YourTable order by SomeField limit $offset,  $limit";  //Change YourTable like u did above. Chagne SomeField to which ever Column in MySQL you want to order the rows by alphabetically.
    $result = mysql_query($query);  

    // use $result here to output page content
	 $num=mysql_numrows($result);
	 $lo=0;
     while ($lo < $num) {
	 $SomeVariable1=mysql_result($result,$lo,"SomeField"); // Replace $SomeVariable with anything. Than you may echo it below. Replace SomeField with first column u want to display from MySQL
     $SomeVariable2=mysql_result($result,$lo,"SomeField"); //Same as above but change SomeField to the second Column in MySQL you want to display.
	 
	 echo "<b>$SomeVariable1</b><br><br>$SomeVariable2<br><br>"; //Replace with your variables from above.
	 
	 ++$lo;
}
?>
<?

    // output paging system (could also do it before we output the page content) 
    if ($page == 1) // this is the first page - there is no previous page 
        echo "Previous";  
    else            // not the first page, link to the previous page 
        echo "<a href="ThisScript.php?page=" . ($page - 1) .  "">Previous</a>";  //Just put the url to this script but include the ?page=
  

    for ($i = 1; $i <= $pager->numPages; $i++) {  
        echo " | ";  
        if ($i == $pager->page)  
            echo "Page $i";  
        else  
            echo "<a href="ThisScript.php?page=$i">Page $i</a>";  //Just put the url to this script and add ?page=$i. ($i gets the page number)
    }  

    if ($page == $pager->numPages) // this is the last page - there is no next page 
        echo "Next";  
    else            // not the last page, link to the next page 
        echo "<a href="ThisScript.php?page=" . ($page + 1) . "">Next</a>";  //Just put the url to this script but include the ?page=
?>
I hope this helps someone. Ive gotten alot of help from you people here. Hopefully this will make it easier on people doing pagination.
Last edited by mikegotnaild on Wed Feb 18, 2004 6:30 pm, edited 12 times in total.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

You could try changing this line (appears 3 times !!!):
echo "<a href=\"http://naild.com/localmm/modules.php?na ... stic?page="

with this

echo "<a href=\"http://naild.com/localmm/modules.php?na ... acoustic[b]&[/b]page="
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

well ya dont gotta get snooty :) Thanks though. Im just not really good with syntax and lack the expirience.. Ive only started learning php not too long ago.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

It works now ?

Cheers,

Dr Evil
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

yes it does thanks
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

Now i just gotta figure out some coding so that each individual Band_Name can be a link to its own page so that each band can have their own personal page.
Post Reply