mATOK Posted May 8, 2007 Share Posted May 8, 2007 Hey there, I hope that someone can give me a hand. I have a multi dimensional array that I would like to print out on multiple pages, 10 elements at a time. Here is what I grab from my SQL - $q="SELECT * FROM print_notes ORDER BY effective_date DESC"; $rez=mysql_query($q) or die (mysql_error()); I then proceed to iterate through the array printing out various elements... while ($i = mysql_fetch_array($rez) Now I want only 10 elements per page and am unsure how to go about this... I was thinking perhaps of adding a count like: while ($i = mysql_fetch_array($rez) AND $num < 10) { $num++; But I don't know how to start the next page at the 11th element in the array. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/ Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 your thinkin bout it a little backwards... dont limit the while()... limit the query... $result=db_query("SELECT * FROM updater_photos WHERE `category`='1'"); $num=mysql_num_rows($result); if(!is_numeric($_GET )) $page=1; else $page=$_GET ; $limit=12; $start = $page * $limit - ($limit); $result = db_query("SELECT * FROM updater_photos WHERE ORDER BY id LIMIT $start, $limit"); then you just ?page=2 Quote Link to comment https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/#findComment-248120 Share on other sites More sharing options...
mATOK Posted May 9, 2007 Author Share Posted May 9, 2007 Thank you for your help but I am not sure I get it... wouldnt I need to find out how many elements exist in the db and then select the first 10, then the next 10 etc ?? Quote Link to comment https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/#findComment-249278 Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 yup! then use how many items/limit, to build a list of #s that direct to each page :-) Quote Link to comment https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/#findComment-249332 Share on other sites More sharing options...
mATOK Posted May 23, 2007 Author Share Posted May 23, 2007 Ok I got this far $num = mysql_num_rows($rez); if(!is_numeric($_GET )) { $page=1; } else $page=$_GET ; $limit=12; $start = $page * $limit - ($limit); $result = mysql_query("SELECT * FROM print_notes ORDER BY print_note_num LIMIT $start, $limit") or die (mysql_error()); while ($i = mysql_fetch_array($result)) { how would I go about creating a page2? Quote Link to comment https://forums.phpfreaks.com/topic/50500-printing-our-an-array-on-multiple-pages/#findComment-259854 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.