DarkPrince2005 Posted August 21, 2007 Share Posted August 21, 2007 I have the following working code whic was the most simple example I could find on pagination.... <?php mysql_connect("localhost","root",""); mysql_select_db("npa"); /* Shows "The Horse's Mouth" Blog at 10 entires per page, including links to see the other pages. */ $perpage = 1; $lynx = $html = ""; $startat = $_REQUEST * $perpage; $q = mysql_query("select count(File_Ref) from disciplinaries"); $row = mysql_fetch_array($q); $pages = ($row[0] + $perpage - 1) / $perpage; $q = mysql_query("select * from disciplinaries order by File_Ref desc limit $startat,$perpage"); while ($row = mysql_fetch_assoc($q)) { $text = strip_tags($row[entry_text]); $text = substr($text,0,300); $html .= "<dt><html><head><title></title><link rel='stylesheet' href='stylesheet.css' type='text/css'> <style> a:link{font-family:'Verdana','Helvetica'; font-size:8pt; color:'#000000'; font-weight:700; text-decoration:none; } a:visited{font-family:'Verdana','Helvetica'; font-size:8pt; color:'#000000'; font-weight:700; text-decoration:None; } a:hover{font-family:'Verdana','Helvetica'; font-size:8pt; text-decoration:none; color:'#000000'; font-weight:700; } a:active{font-family:'Verdana','Helvetica'; font-size:8pt; color:'#ffffff'; font-weight:700; } </style></head><body bgcolor='#FDCC67'><h1>View Disciplinary Hearings</h1> <table><tr><td><b>File Ref</td><td> </td> <td>$row[File_Ref]</td></tr> <tr><td><b>Employee:</td><td> </td> <td>$row[Employee]</td></tr> <tr><td><b>Occupation</td><td> </td> <td>$row[Occupation]</td</tr> <tr><td><b>Gender and Race</td><td> </td> <td>$row[Gender_Race]</td</tr> <tr><td><b>Suspension</td><td> </td> <td>$row[suspensions]</td</tr> <tr><td><b>Period</td><td> </td> <td>$row[Period]</td></tr> <tr><td><b>Date Recieved</td><td> </td> <td>$row[Date_Recieved]</td</tr> <tr><td><b>Unit</td><td> </td> <td>$row[unit]</td</tr> <tr><td><b>Region</td><td> </td> <td>$row[Region]</td</tr> <tr><td><b>Date Of DC</td><td> </td> <td>$row[Date_Of_DC]</td</tr> <tr><td><b>Status</td><td> </td> <td>$row[status]</td></tr> <tr><td><b>Category</td><td> </td> <td>$row[Category]</td></tr> <tr><td valign='top'><b>Status Report</td><td> </td> <td width='600'>$row[status_Report]</td></tr> <tr><td><b>Outcome</td><td> </td> <td>$row[Outcome]</td></tr></table><br> - <a href=/mouth/$row[File_Ref]_.html target=pix>$row[entry_title]</a></dt><br>"; //$html .= "<dd>$text ....<br><br></dd>"; }; for ($k=0; $k<$pages; $k++) { if ($k != $_REQUEST ) { $lynx .= " <a href=$PHP_SELF"."?page=$k>".($k+1)."</a>"; } else { $lynx .= " <b>--".($k+1)."--</b>"; } } ?> <html> <head><title></title> </head> <body><center><br> <?= $html ?> <?= $lynx ?> </body> But I want to change the navigational links to be displayed as First,Previous,Next and Last... Hopefully by only modifying my current script.... Link to comment https://forums.phpfreaks.com/topic/65927-solved-pagination/ Share on other sites More sharing options...
AdRock Posted August 21, 2007 Share Posted August 21, 2007 I found this script ages ago that does google style pagination that does exactly what you want and you can even set the number of links per page. I can't remember where i found it so i can't tell you Here is the code I use for the pagination <h2>News / Events</h2><hr /> <div> <?php include "includes/connection.php"; $webpage = basename(news); //Basename is the name of the page you are using the pagination i.e. article.php function pagination_five($total_pages,$page){ global $webpage; $max_links = 10; //This can be changed $h=1; if($page>$max_links){ $h=(($h+$page)-$max_links); } if($page>=1){ $max_links = $max_links+($page-1); } if($max_links>$total_pages){ $max_links=$total_pages+1; } if($total_pages>1){ echo '<div class="page_numbers"><ul>'; if($page>"1"){ echo '<li class="current"><a href="/'.$webpage.'/1">First</a></li> <li class="current"><a href="/'.$webpage.'/'.($page-1).'">Prev</a></li> '; } if($total_pages!=1){ for ($i=$h;$i<$max_links;$i++){ if($i==$page){ echo '<li><a class="current">'.$i.'</a></li>'; } else{ echo '<li><a href="/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($page >="1")&&($page!=$total_pages)){ echo '<li class="current"><a href="/'.$webpage.'/'.($page+1).'">Next</a></li> <li class="current"><a href="/'.$webpage.'/'.$total_pages.'">Last</a></li> '; } echo '</ul></div>'; } } $result = mysql_query("Select count(*) from news WHERE archived='n'") or die (mysql_error()); $numrows = mysql_fetch_row($result); if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); //after we have $total_pages and $page, we can include the //pagination style wherever we want on the page. //so far there is no output from the script, so we could have //pagination before or after the pages results //before the results $result = mysql_query("SELECT id,title,content, DATE_FORMAT(time, '%W %D %M %Y') as date, photo, alternate FROM news WHERE archived='n' ORDER BY id DESC LIMIT $offset,$entries_per_page"); if(!$result) die(mysql_error()); $err = mysql_num_rows($result); if($err == 0) die("No matches met your criteria."); while($row=mysql_fetch_array($result)){ $title = htmlentities(strtoupper($row['title'])); $content = htmlentities($row['content']); if (!$row['photo']){ echo "<div id='right'><h3>".$title."</h3><p class='italic'>Date added: ".$row['date']."</p><p>".nl2br($content)."</p><br /></div>\n"; } else { echo "<div id='right'><h3>".$title."</h3><p class='italic'>Date added: ".$row['date']."</p><p><img src='/images/large/".$row['photo']."' alt='".$row['alternate']."' class='right' />".nl2br($content)."</p><br /></div>\n"; } } //or after the results pagination_five($total_pages,$page); ?> </div> Here is the stylesheet for the pagination .page_numbers { width: 600px; padding: 5px 0px; float:left; clear:left; margin:0 auto; } .page_numbers ul { margin: 0 auto; list-style-type: none; padding: 0px; text-align: center; } .page_numbers li { display: inline; float: left; margin:1px; background: #a7a7a7; width:25px; } .page_numbers li.current{ width:50px; } .page_numbers li a { background: #fff; border: 1px solid #a7a7a7; padding: 1px; text-decoration: none; color: #000; font:bold 8px verdana,sans-serif; display:block; } .page_numbers a.current, .page_numbers li a:hover { background: #a7a7a7; color: #fff; } I've included the original functions so you can choose which style you want to use [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/65927-solved-pagination/#findComment-329685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.