cyprus Posted September 24, 2006 Share Posted September 24, 2006 I have an HTML table that dynamically fills from a select query. It works well however I have to think about curbing its height, otherwise my page will be a few miles high. Anybody got a suggestion as to avoiding such a disaster? Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php Quote Link to comment Share on other sites More sharing options...
cyprus Posted September 24, 2006 Author Share Posted September 24, 2006 Thankyou, I have printed the tutorial and have a read tomorow. Looks quite a lot to do, I will cut out color changes unless I can use it to identify product groups in my html table. Also I don't know how its going to slide into my select queries. Probably all makes sense if I read it - I will. Thanks again Quote Link to comment Share on other sites More sharing options...
cyprus Posted September 25, 2006 Author Share Posted September 25, 2006 I cut and pasted all the code from the first example into a page, amended all db references, and it just produced a series of n's at the left hand side, the links to goto the next page were dead? Any ideas why it does not burst into life? Thanks. Quote Link to comment Share on other sites More sharing options...
cyprus Posted September 25, 2006 Author Share Posted September 25, 2006 Thought I would post the code in case something was clearer why it did not work. Regards[code]<?session_start();$_SESSION['Dayte']=date("F j, Y, g:i a");?><?php $username="root";// $password="password";$database="Forders";mysql_connect(localhost,$username);mysql_select_db($database) or die( "Unable to select database"); //$result = mysql_query($query) or die('Problem with query: ' . $query . '// '. mysql_error()); $limit = 10; $query_count = "SELECT count(Ordernumber) 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 Ordernumber 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["Orderdate"]); echo("</td>n<td>"); } echo("</table>"); if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> </html>[/code]MOD EDIT - code tags added. Please use them. Quote Link to comment Share on other sites More sharing options...
sasa Posted September 25, 2006 Share Posted September 25, 2006 1 st change [code]$totalrows = mysql_num_rows($result_count); [/code]to[code]$totalrows = mysql_result($result_count,0,0); [/code]2nd change[code]$pageprev = $page--; [/code]to[code]$pageprev = $page-1; [/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted September 25, 2006 Share Posted September 25, 2006 Please accept my aplogies for directing you to that.Only read the first 6 rows to see there's some crap code in there. That first query will only return 1 row yet they are trying to use mysql_num_rows() to get total rows! They are doing the right thing by getting COUNT() but ruin it by not picking up it's value.On to the next bit and $page hasn't been defined (assumes register globals is ON, not uncommon though in older tutorials) Quote Link to comment Share on other sites More sharing options...
cyprus Posted September 25, 2006 Author Share Posted September 25, 2006 Thanks both. I changed the bits sasa suggested, and that brought the page navigation keys alive apart from the Previous link. Its a shame, thought that would have sorted things out using this code, however will junk it and try and find other code. Again thanks both of you for trying to help. Quote Link to comment Share on other sites More sharing options...
cyprus Posted September 26, 2006 Author Share Posted September 26, 2006 Anbody following my footsteps, this reference helped me and worked. Hope it helps someone else.http://www.tonymarston.net/php-mysql/pagination.html 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.