html - PHP Pagination Bug with Twitter Bootstrap -
i have bug in program pagination links not show @ when $page_rows
greater 1.
<?php require('/inc.all.php'); $_session['lasturl'] = $_server['request_uri']; // total count of rows $sql = "select count(username) user_profile hidefromusercount='0'"; $query = $db->query($sql); $row = $query->fetch_row(); // total row count $rows = $row[0]; //number of results per page $page_rows = 3; //tells number of last page $last = ceil($rows/$page_rows); if($last < 1) $last = 1; //establish $pagenum variable $pagenum = 1; if(isset($_get['pg'])) $pagenum = preg_replace('#[^0-9]#', '', $_get['pg']); else $pagenum = 1; //makes sure pagenumber isnt below 1 or more $last if($pagenum < 1) $pagenum = 1; else if($pagenum > $last) $pagenum = $last; //sets range of rows chosen $pagenum $limit = 'limit '.($pagenum-1) * $page_rows.','.$page_rows; $sql = "select username user_profile hidefromusercount='0' order username asc $limit"; $query = $db->query($sql); $show_start = $pagenum * $page_rows; $show_end = (($pagenum * $page_rows) + $page_rows)-1; $textline1 = "total profiles: <b>$rows</b>"; $textline2 = "page <b>$pagenum</b> of <b>$last</b>"; $paginationctrls = ''; if($last != 1){ if($pagenum > 1){ $previous = $pagenum-1; $paginationctrls .= "<li><a href=\"?pg=$previous\">prev</a></li>"; for($i = $pagenum-4; $i < $pagenum; $i++){ if($i > 0){ $paginationctrls .= "<li><a href=\"?pg=$i\">$i</a></li>"; } } }else{ $previous = $pagenum-1; $paginationctrls .= "<li class='disabled'><a href=\"#\">prev</a></li>"; } $paginationctrls .= "<li class='disabled'><a href=\"#\">$pagenum</a></li>"; for($i = $pagenum+1; $i<=$last; $i++){ $paginationctrls .= "<li><a href=\"?pg=$i\">$i</a></li>"; if($i >= $pagenum+4){ break; } } if($pagenum != $last){ $next = $pagenum +1; $paginationctrls .= "<li><a href=\"?pg=$next\">next</a></li>"; }else{ $next = $pagenum +1; $paginationctrls .="<li class=\"disabled\"><a href=\"#\">next</a></li>"; } $usernames = ""; while($row = $query->fetch_assoc()){ $username = $row['username']; $usernames .="<br><a href=\"viewprofile?usr=$username\">$username</a><br>"; } } ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>minecraft profiles | profiles</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style/css/style_viewprofile.css"> <link href="style/css/bootstrap.css" rel="stylesheet" type="text/css"> </head> <body> <div class="navbar navbar-fixed-top"> <div class="navbar-inner"> <a class="brand" href="index">minecraft profiles</a> <ul class="nav"> <li><a href="index">home</a></li> <li class="active"><a href="profilelist">profiles</a></li> <li><a href="userlookup">find user</a></li> <li><a href="createprofile">create profile</a></li> <li><a href="dashboard">user dashboard</a></li> <?php if(isset($_session['username']) && isset($_session['password'])){ echo "<li><a href=\"logout\"> welcome back, ".$_session['username']."! click log out</a></li>"; }else{ echo "<li><a href=\"login\">login</a></li>"; } ?> </ul> </div> </div> <br /> <br /> <div id="header"> <h1>profiles</h1> </div> </div> <div id="content"> <div id="sidebar"> <strong>featured profiles</strong> <br /> <?php $sql = "select username user_profile featured = 1"; $query = $db->query($sql); while($row = $query->fetch_assoc()){ $username = $row['username']; echo "<a href=\"viewprofile.php?usr=$username\">$username</a>"; echo "<br />"; } ?> </div> <div id="main"> <center> <?php echo $textline1;?><br /> <?php echo $textline2; ?><br /> <?php if(isset($usernames)) {echo $usernames; }?><br /> <div class="pagination"><ul><?php echo $paginationctrls; ?></ul></div></center> </div> <div class="clear"> <?php $sql="select * user_profile hidefromusercount = 0"; $query=$db->query($sql); echo "<div class=\"clear\"><br /><center>minecraft profiles proud have ".$query->num_rows." unique profile(s) registered in our databases!</center></div>"; ?> </div> </div> </body> </html>
when $page_rows
greater 1, happens:
$last = ceil($rows/$page_rows);
so, if have $rows = 3 , $page_rows = 3 (set on start of page) $last 1 (1 / 1 = 1)
"page <b>$pagenum</b> of <b>$last</b>";
echoes
page 1 of 1
and this: if($last != 1){
stops else.
you should add @ least 1 row see change (so $last 2)
Comments
Post a Comment