Canman2005 Posted June 16, 2009 Share Posted June 16, 2009 Hi all I have a couple of questions based on foreach ($rss->items as $item) { } if you're able to help. 1: Is it possible to define a variable that will give me a total number of results in the foreach statement? 2: Is it possible to archive a page numbering system with foreach? Thanks everyone Dave Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/ Share on other sites More sharing options...
GingerRobot Posted June 16, 2009 Share Posted June 16, 2009 1: Is it possible to define a variable that will give me a total number of results in the foreach statement? You mean, like start a counter and increment it each time it runs? $counter = 0; foreach ($rss->items as $item) { $counter++; } 2: Is it possible to archive a page numbering system with foreach? Sorry? Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857088 Share on other sites More sharing options...
Canman2005 Posted June 16, 2009 Author Share Posted June 16, 2009 sorry, I mean a page numbering system, so for example, if you have 10 results in your foreach ststement you could display two of those ten per page over 5 pages if that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857089 Share on other sites More sharing options...
Canman2005 Posted June 16, 2009 Author Share Posted June 16, 2009 with your solution, is it possible just to grab the last value so that rather than 1 2 3 4 5 6 it would just display 6 as a total? thanks Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857091 Share on other sites More sharing options...
Canman2005 Posted June 16, 2009 Author Share Posted June 16, 2009 ok, I have figured out the first issue I had by doing $row = 1; foreach ($rss->items as $item) { $rowsnum = $row++; } print $rowsnum; that seemed to work fine. I guess I can figure out page numbering based on the total number returned. Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857107 Share on other sites More sharing options...
Canman2005 Posted June 16, 2009 Author Share Posted June 16, 2009 and figured out page numbering with $pages = 1; $totalpages = $rowsnum/2; for ($i = 0; $i < $totalpages; $i++) { print $pages++.' | '; } Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857121 Share on other sites More sharing options...
Canman2005 Posted June 16, 2009 Author Share Posted June 16, 2009 solved it thanks for the inital comments, got me on the right track Quote Link to comment https://forums.phpfreaks.com/topic/162382-solved-foreach-pagination/#findComment-857130 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.