scottish_jason Posted February 1, 2010 Share Posted February 1, 2010 hi guys, another little problem I am trying to display a list of information inserted into the database in DESC order, but only want to display 20 row's and then a section where the user can go back or forward a page on to the previous 20 or the next 20, if that makes any sense. I got it working to a certain extent by messing around with different things but it would not display the very last stuff on the 1st page but on the 2nd, or also with different code I had it display the newest additions on the first page but in reverse order. Here is my current code mysql_connect("localhost","forum","forum") or die(mysql_error()); mysql_select_db("forum") or die(mysql_error()); $genree = $_GET['genre']; $currentpage = $_GET['page']; $currentpage0 = ($currentpage - 1); $currentpage2 = ($currentpage + 1); $query = mysql_query("SELECT MAX(id) AS maximum FROM mixes"); list ($maxid1) = mysql_fetch_row($query); $maxid2 = (20*$currentpage); $maxid3 = $maxid2 - 20; if ($currentpage == 1) { $maxid2 = 20; $maxid3 = 0; } var_dump ($maxid3); var_dump ($maxid2); //query the db $getmixes = mysql_query("SELECT * FROM mixes WHERE genre='$genree' AND id >= '$maxid3' AND id <= '$maxid2' ORDER by id DESC") or die(mysql_query()); $i = 1; while ($row = mysql_fetch_assoc($getmixes)) { $mixtitle = $row['title']; $id = $row['id']; $poster = $row['poster']; $url = $row['url']; echo "<a href='$url'>$mixtitle"; echo "<br>"; if ($i >= 19) break; $i++; } $genree = $_GET['genre']; $currentpage = $_GET['page']; ?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage0 ?>"><</a><?php echo " page $currentpage ";?> <a href="http://localhost/mixes.php?genre=<?php echo $genree ?>&page=<?php echo $currentpage2 ?>">></a><?php; so what the above currently does is on page 1 displays ID 0-20, page 2 displays ID 20-40 which is kind of right but not quite, I want it display the last ID at the top of page 1 and the very first addition on the last page at the bottom. I was playing around with finding the max ID in the database and then attempting to work out which id chunk that it should output but that got messy. I know im probably doing this the wrong way but im new to PHP and still trying to learn the better methods of doing such things, what would be a good way to do what I require? thanks for your time and help! Link to comment https://forums.phpfreaks.com/topic/190536-list-info-from-database-with-page-x-facility/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.