Jump to content

Pagination


pro_se

Recommended Posts

k, so i have my previous and next links working (GREAT)

but what i cannot figure out is how to put the individual pages (page 1, page2, page3)

ex. [prev.] [page1] [page2] [next]

k so i know i have to divide the number of rows by how many i am showing rows i am showing on the page to get the total of pages but how would i make it count 1, 2 to 3

here is the code i have for the prev. next pages:
[code]<?php
include '/home/*********/inc/config_db.php';
$sql125 = "SELECT *
FROM `users`";
  $rowstart = $_GET['pfg'];
if(!$_GET['pfg']) $rowstart=0;
$sql = "SELECT * FROM users order by username asc limit $rowstart,5";
  $result = mysql_query ($sql, $connection);
while($row=mysql_fetch_array($result)) {
  $userid = $row["userid"];
  $first_name = $row["first_name"];
  $last_name = $row["last_name"];
  $username = $row["username"];
  $email_address = $row["email_address"];
  $setting_email = $row["setting_email"];
  $setting_files = $row["setting_files"];
  $activated = $row["activated"];
  echo "<div style=\"background: url(http://images.*********.net/browse_bg.gif); background-repeat: repeat-y; padding-left: 6px;\"><i>$first_name $last_name</i><br />$username<br />";
if ($setting_email == '1') {
echo "<a href=mailto:$email_address>$email_address</a><br />"; } else {
echo "* email hidden *<br>"; }
if ($setting_files == '1') {

echo "Files: (private)</div><br>";
} else {
echo "Files: "; $sql2    = "SELECT * FROM image where userid=$userid";
$result2 = mysql_query ($sql2, $connection);
$num = mysql_num_rows ($result2);
  echo "$num";
echo " <a href=viewuser.php?userid=$userid>(view)</a></div><br>
    ";
}
}

//initialize the start to 0


//put all the code here for running the script itself using $result in the while loop

//put where you want the next prev to appear
$result125 = mysql_query ($sql, $connection);
  $numrows = mysql_num_rows($result125);
echo '<p>';
if($rowstart+5>$numrows)
{
  echo "<A HREF=\"$php_self?pfg=";$minus = $rowstart-5;echo "$minus\">< Previous Page</A> ";
}
if($rowstart-5<$numrows)
{
  echo "<A HREF=\"$php_self?pfg=";$plus = $rowstart+5;echo "$plus\">Next Page ></A>";
}
echo '</p>';
?>[/code]
Link to comment
Share on other sites

If you simply want to show all of the available pages, then just use a loop:

[code]
<?php
$pages = ceil($numrows/5);
$i = 0;
while($i <= $pages){
$rownumber = $i * 5;
echo $rownumber;
echo " <A HREF='$php_self?pfg=$rownumber'>Page $i</A> ";
$i++;
}
?>
[/code]

If you wanted to show, say 2-3 pages each side of the current page then it gets a little more complicated, but its just going to require a few if statements.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.