pro_se Posted January 13, 2007 Share Posted January 13, 2007 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]<?phpinclude '/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] Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 13, 2007 Share Posted January 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted January 13, 2007 Share Posted January 13, 2007 This [url=http://www.phpfreaks.com/tutorials/147/0.php]Expanded Pagination[/url] tutorial shows how to limit the numbers to the left and right of the current page, if you're looking to do that. If you just want it to show all the numbers then just loop through all of them as suggested. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.