FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Pagination?





Diablosblizz
Does anybody have a easy to install Pagination? I need it for my members system, I have like one LONG page filled with 300 members.

It doesn't need to have the << Prev and Next >>, just page numbers will do.

If possible, you can just code it into this:

Code:
default:
echo "<table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>

   <tr>
   <td width='40%'>&nbsp;<font size='1'><b>Username</b></td>
   <td width='40%'><font size='1'><b>Private Message</b></td>
   </tr>
   </table>";
$getusers = mysql_query("SELECT * FROM `members`") or die(mysql_error());
while ($users = mysql_fetch_array($getusers)) {
echo "   <table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>

   <tr>
   <td width='40%'><li><font size='1'><a href='?page=view&username=$users[username]'><font size='1'>$users[username]</a></td>
   <td width='40%'><a href='pms.php?page=compose&user=$users[username]'><font size='1'>Private Message</a></li></td>
   </tr>
   <tr>
   
</tr>
   </table>";
}
echo '*************************** ////////// PUT PAGINATION HERE \\\\\\\\\\ ***************************';
break;



There is more of the code, but it's not needed. I've tried like 5 paginations, and I cannot get it!

Many thanks to whoever does this!


EDIT: Re-looked the code, the pagination would have echoed itself for each user.
mathiaus
Try this. Don't be surprised if it doesn't work though, it hasn't been tested or even looked over properly.

Code:
default:
   echo "<table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>

      <tr>
      <td width='40%'>&nbsp;<font size='1'><b>Username</b></td>
      <td width='40%'><font size='1'><b>Private Message</b></td>
      </tr>
      </table>";
      
   // PAGINATION
   $per_page = 50; // Number of users to display per page

   // Count all of the users
   $num_users = mysql_query('SELECT COUNT(*) AS num_users FROM `members`');
   $num_users = fetch_row($num_users);
   $num_users = $num_users['num_users'];
   // Number of pages required
   $num_pages = $num_users / $per_page;

   // What page are we currently on?
   $cur_page = isset($_GET['page']) ? $_GET['page'] + 1 : 2;
   //Whats our starting point?
   $start = ($cur_page - 1) * $per_page;
   $getusers = mysql_query('SELECT * FROM `members` LIMIT '.$start.', '.$per_page.'\'') or die(mysql_error());
   while ($users = mysql_fetch_array($getusers)) {
      echo "   <table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>
         <tr>
         <td width='40%'><li><font size='1'><a href='?page=view&username=$users[username]'><font size='1'>$users[username]</a></td>
         <td width='40%'><a href='pms.php?page=compose&user=$users[username]'><font size='1'>Private Message</a></li></td>
         </tr>
         <tr>
         
      </tr>
         </table>";
   }
   
   
   // MORE PAGINATION (the actual page links)
   $i = 1;
   while($i <= $num_pages) {
      echo '<a href="?page='.$i.'">'.$i.'</a>&nbsp;';
   }
   
   
break;
Diablosblizz
Web Server wrote:
Fatal error: Call to undefined function fetch_row() in C:\xampp\htdocs\Hotel Mario\members\members.php on line 21


Line 21:

Code:
20                $num_users = mysql_query('SELECT COUNT(*) AS num_users FROM `members`');
21                $num_users = fetch_row($num_users);
22                $num_users = $num_users['num_users'];


I've never heard of fetch_row...
DjinniFire
maybe it's mysql_fetch_row

usually that's how mysql functions work

this tutorial was one I found that worked great
I use it for anything that I need to have pagination
http://www.phpfreaks.com/tutorials/43/0.php
it's simple enough but it might take some understanding of the coding first before u figure out integration

I don't have time to do much coding as I have a heavy load of homework to do in 2 days x]
Diablosblizz
I tried this already, did the copy and paste thing. Razz Didn't work out so well. I also tried the mysql_fetch_row and I get this:

Web Server wrote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1
mathiaus
I can't believe I posted that rubbish. I've looked at this again, while I was awake this time. It's also now tested :)

Code:
default:
   echo "<table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>

      <tr>
      <td width='40%'>&nbsp;<font size='1'><b>Username</b></td>
      <td width='40%'><font size='1'><b>Private Message</b></td>
      </tr>
      </table>";
     
   // PAGINATION
   $per_page = 50; // Number of users to display per page

   // Count all of the users
   $num_users = mysql_query('SELECT COUNT(*) FROM `members`');
   $num_users = mysql_fetch_row($num_users);
   $num_users = $num_users[0];
   // Number of pages required
   $num_pages = ceil($num_users / $per_page);

   // What page are we currently on?
   $cur_page = isset($_GET['page']) ? $_GET['page'] : 1;
   //Whats our starting point?
   $start = ($cur_page - 1) * $per_page;
   $query = 'SELECT * FROM `subs` LIMIT '.$start.', '.$per_page;
   $getusers = mysql_query($query) or die(mysql_error());
   while ($users = mysql_fetch_array($getusers)) {
      echo "   <table width='80%' align='center' border='0' cellspacing='2' cellpadding='2'>
         <tr>
         <td width='40%'><li><font size='1'><a href='?page=view&username=$users[username]'><font size='1'>$users[username]</a></td>
         <td width='40%'><a href='pms.php?page=compose&user=$users[username]'><font size='1'>Private Message</a></li></td>
         </tr>
         <tr>
         
      </tr>
         </table>";
   }
   
   
   // MORE PAGINATION (the actual page links)
   $i = 1;
   while($i <= $num_pages) {
      echo '<a href="?page='.$i.'">'.$i.'</a>&nbsp;';
     $i++;
   }
   
   
break;
Diablosblizz
Thank you very much Mathiaus! Work's perfectly, thank you!!

Smile
DjinniFire
add at the bottom :]

before the showing of page numbers
Code:


   if($cur_page >1) {
      $prev=$cur_page-1;
      echo '<a href="?page='.$prev.'"><<Prev</a>&nbsp;';
   }



and this after showing of all pages

Code:


   if($cur_page <$num_pages) {
      $next=$cur_page+1;
      echo '<a href="?page='.$next.'">Next >></a>&nbsp;';
   }




I believe that should work in showing Previous and Next
Related topics
PHP Pagination and Tables
PHP DB Error: syntax error
help with pagination problem
Pagination with .html extension
Very basic pagination
Need help - guestbook pagination like [1] [2] [3] etc.
Strange Problem in PHP-MYSQL
Pagination of data from an UNION query
http://tuvanonline.com/library/index.php
PHP-Nuke platium?
PHP Write to line
Anyone good with PHP-NUKE?
PHP safety?
req: PHP to list files in directory, and link to them
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.