otuatail Posted March 28, 2006 Share Posted March 28, 2006 I have a mysql database (4.0.25 I believe – streamline.net) I would like to show the first 10 or so with a Previous 1 2 3 4 next system underneath. I could count the records and work out how many pages, but I would not know the unique id as records could be removed and there would be gaps in the auto numbering. I could re-invent the wheel, but is there a simple system. SQL server has a page system although I never investigated it.Desmond. Quote Link to comment Share on other sites More sharing options...
Eddyon Posted March 28, 2006 Share Posted March 28, 2006 [a href=\"http://www.phpfreaks.com/tutorials/43/0.php\" target=\"_blank\"]Pagination: Easy as PREV 1 2 3 NEXT[/a]Nice tutorial there from TheReverend.And here is another, this time by phpfreak.[a href=\"http://www.phpfreaks.com/tutorials/73/1.php\" target=\"_blank\"]Page Numbering With PHP And MySQL Results[/a] Quote Link to comment Share on other sites More sharing options...
lansing Posted April 13, 2006 Share Posted April 13, 2006 [!--quoteo(post=359252:date=Mar 28 2006, 08:03 AM:name=Eddyon)--][div class=\'quotetop\']QUOTE(Eddyon @ Mar 28 2006, 08:03 AM) [snapback]359252[/snapback][/div][div class=\'quotemain\'][!--quotec--][a href=\"http://www.phpfreaks.com/tutorials/43/0.php\" target=\"_blank\"]Pagination: Easy as PREV 1 2 3 NEXT[/a]Nice tutorial there from TheReverend.And here is another, this time by phpfreak.[a href=\"http://www.phpfreaks.com/tutorials/73/1.php\" target=\"_blank\"]Page Numbering With PHP And MySQL Results[/a][/quote]I have been trying different things to get this code to work for days now. I used that [b]Pagination: Easy as PREV 1 2 3 NEXT[/b]. My code isn't showing the [b][i]PREV[/i][/b] & [b][i]NEXT [/i][/b]as links. I don't have any links to navigate to different pages. I think it has something to do with checking to see if the [i][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]?page=1[!--colorc--][/span][!--/colorc--][/i] or the [i][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]?page=2[!--colorc--][/span][!--/colorc--][/i] in the url is there or not. I don't see any code for that.Like in the [b]Page Numbering With PHP And MySQL Results[/b] tutorial it has coding like this which the other tutorial doesn't. I can get lnks in the 2nd tutorial, but I like the first one better.[code]if(!isset($_GET['page'])){ $page = 1;} else { $page = $_GET['page'];}[/code]This is the code for my page![code]<?php //@mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); //@mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); $limit = 5; $query_count = "SELECT count(*) FROM orders"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM orders LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#E0E0E0"; // light gray echo("<table>"); while($row = mysql_fetch_array($result)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } echo("<tr bgcolor=".$bgcolor.">n<td>"); echo($row["order_id"]); echo("</td>n<td>"); echo($row["customers_id"]); echo("</td>n</tr>"); } echo("</table>"); if($page != 1){ $pageprev = $page--; echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$pageprev\">PREV</a> "); }else{ echo("PREV"); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$pagenext\">NEXT ".$limit."</a>"); }else{ echo("NEXT ".$limit); } mysql_free_result($result);?>[/code] 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.