freemancomputer Posted March 9, 2012 Share Posted March 9, 2012 Ok so I thought my pagination was working just fine until I took a closer look at the database. Turns out its not showing everything that it should. With the way I Have it now it only shows 2 pages of 40 items, there is closer to 60 that should be shown. I moved it to show only 15 per page to see if it was an error with the page reading but it showed only 3 pages for a total of 45 items. Here is what i have right now with is showing the 20 per page. Any ideas? <?php session_start(); $rank=$_SESSION['rank']; $loggedinusername=$_SESSION['loggedinusername']; $loggedinuseremail=$_SESSION['loggedinuseremail']; ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Drink To The Credits</title> <link href="mainstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <div id="header"> <?php include_once"header.php" ?></div> <div id="content"> <?php include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or trigger_error("SQL", E_USER_ERROR); $sql = "SELECT COUNT(*) FROM movies WHERE type LIKE 'movie'"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $rowsperpage = 20; $totalpages = ceil($numrows / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $sql = "SELECT title FROM movies ORDER BY title LIMIT $offset, $rowsperpage" ; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); ?> <table width="70%" align="left"> <tr> <td align="center" class="rulesub">Movies</td> </tr> <?php while ($list = mysql_fetch_assoc($result)) { ?> <tr> <td> <a class="nav" href=/rules.php?title=<?php echo urlencode($list['title']); ?>><?php echo $list['title']; ?></a> <br /> <?php } $range = 3; if ($currentpage > 1) { echo " <a class='nav' href='<?php movies.php?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a class='nav' href='movies.php?currentpage=$prevpage'><</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a class='nav' href='movies.php?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a class='nav' href='movies.php?currentpage=$nextpage'>></a> "; echo " <a class='nav' href='movies.php?currentpage=$totalpages'>>></a> "; } // built with a tutorial from php freaks ?> </table> </div> <div id="sidecontent"><?php include_once"newmovies.php" ?></div> <div id="footer"> <?php include_once"footer.php" ?></div> </body> </html> I am also looking to have the out put broken into 2 columns so there would be 40 per page. Sorry if the post is rambling, lacking on the sleep so I shall be heading to bed. Link to comment https://forums.phpfreaks.com/topic/258570-pagination-only-retruning-part-of-the-output/ Share on other sites More sharing options...
q11we Posted March 9, 2012 Share Posted March 9, 2012 Code seems perfect to me. Just that, how about changing $sql = "SELECT title FROM movies ORDER BY title LIMIT $offset, $rowsperpage" ; to $sql = "SELECT title FROM movies WHERE type LIKE 'movie' ORDER BY title LIMIT $offset, $rowsperpage" ; Link to comment https://forums.phpfreaks.com/topic/258570-pagination-only-retruning-part-of-the-output/#findComment-1325438 Share on other sites More sharing options...
freemancomputer Posted March 9, 2012 Author Share Posted March 9, 2012 Thanks that looks to have fixed it. Is it just doing a 2nd look at the type part of it? Not sure if I understand why that would need to be in both spots. Link to comment https://forums.phpfreaks.com/topic/258570-pagination-only-retruning-part-of-the-output/#findComment-1325440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.