searls03 Posted January 15, 2012 Share Posted January 15, 2012 so my database has a page number next to each field. What I need to know how to do is make it so that the paging number, ie being able to select the page, if greater than one, will display 1-whatever the highest page number is. does this make sense? any help is appreciated. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 16, 2012 Share Posted January 16, 2012 SELECT MIN(column) AS first, MAX(column) AS last FROM table Quote Link to comment Share on other sites More sharing options...
searls03 Posted January 16, 2012 Author Share Posted January 16, 2012 is that a query code? how do I implement it. here is some code: <?php $sql = mysql_query("SELECT MIN(page123) AS first, MAX(page123) AS last FROM products"); while($row = mysql_fetch_array($sql)){ $page = $row['page123']; echo $page; } ?> Quote Link to comment Share on other sites More sharing options...
searls03 Posted January 16, 2012 Author Share Posted January 16, 2012 sorry, I just found out how to do it, and you answered exactly what I asked, but not wanted. I didn't want it to display 1-3 for example, but rather 1 2 3. sorry, again that was my fault. how would I do this? Quote Link to comment Share on other sites More sharing options...
searls03 Posted January 16, 2012 Author Share Posted January 16, 2012 Ok, I am using range, but how do I make it display as a link? currently, nothing shows.... <?php $sql = ("SELECT MIN(page123) AS first, MAX(page123) AS last FROM products"); $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $page1=$row['first']; $page2=$row['last']; } foreach (range($page1, $page2) as $number) { ?> <a href=."<?php $number; ?>".></a> <?php } ?> Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 16, 2012 Share Posted January 16, 2012 Something like: $result = mysql_query("SELECT COUNT(page123) FROM products"); list($count) = mysql_fetch_row($result); for($i = 1; $i <= $count; $i++) { echo $i . ' '; } Quote Link to comment Share on other sites More sharing options...
searls03 Posted January 16, 2012 Author Share Posted January 16, 2012 but how would I do this with the range function that I wrote? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 16, 2012 Share Posted January 16, 2012 You almost had it. <a href="<?php echo $number; ?>"><?php echo $number; ?></a> Quote Link to comment Share on other sites More sharing options...
searls03 Posted January 16, 2012 Author Share Posted January 16, 2012 how would I also make the next/previous buttons, and also make it so that only 10 numbers will be displayed at a time, but no ".....#" so like when it is on page 5, that is when the numbers will start moving so on page 5 it is 234567891011, 6 is 3456789101112. etc Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 16, 2012 Share Posted January 16, 2012 Maybe you should have a look at http://www.phpfreaks.com/tutorial/basic-pagination 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.