mkosmosports Posted February 24, 2007 Share Posted February 24, 2007 Hey, Can anyone help me out regarding the easiest way of displaying foreach array results over multiple pages? Ive seen a tutorial about how to do it for an mysql query but I cant seem to get it together with an array. Any help appreciated.. Thanks.. Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/ Share on other sites More sharing options...
mkosmosports Posted February 24, 2007 Author Share Posted February 24, 2007 Alright, Ive gotten this far: if(isset($_GET['page'])) //If there is a page available { $pageNum = $_GET['page']; } $trcount=0; //Number of loop results variable foreach($trarray as $value) //This is the loop on the main array { $pid = $value['id']; if(isset($_GET['l']) && $_GET['l'] == "2") { $date = substr("{$value['date']}",0,4); $datemon = substr("{$value['date']}",4); $shmon = $_SESSION['months'][$datemon][0]; } else { $date = $value['date']; $shmon = $_SESSION['months'][$date][0]; } $pos = $value['pos']; $nickname = $value['nickname']; $toteam = $value['toteam']; $fromteam = $value['fromteam']; $status = $value['status']; $sum = $value['sum']; if ($date == $mon) //Only looking to retrieve info from a specific month { $trcount++; //Counting number of loop results if (intval($sum) && $sum > "5000000") { echo("<tr style=\"background-color: #F5AA19; font-size: 10px\"><td align=\"center\">$shmon</td><td align=\"center\">$pos</td><td><a href=\"mainstats.html?l=3&player=$pid\"><b>$nickname</b></a></td><td>$fromteam</td><td style=\"font-weight: bold\">$toteam</td><td>$status</td><td><b>$sum</b></td></tr>"); } else { echo("<tr style=\"font-size: 10px\"><td align=\"center\">$shmon</td><td align=\"center\">$pos</td><td><a href=\"mainstats.html?l=3&player=$pid\"><b>$nickname</b></a></td><td>$fromteam</td><td style=\"font-weight: bold\">$toteam</td><td>$status</td><td>$sum</td></tr>"); } } } $maxpage = ceil($trcount/70); //See how many pages are needed based on number of results returned by array $self = $_SERVER['PHP_SELF']; echo("</table>"); if($trcount >= 70) //Only show the page links if there are more than 70 array results { echo("<div style=\"margin: 10px 0px; text-align: center\">"); for($page = 1; $page <= $maxpage; $page++) { echo("<a class=\"trmonsel\" href=\"$self?type=transfers&mon=$mon&page=$page\">page: $page</a>"); } } echo("</div></div>"); Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-192710 Share on other sites More sharing options...
mkosmosports Posted February 24, 2007 Author Share Posted February 24, 2007 bump..bump... , just in case anyone has heard of a successfull to do what Im trying to do... Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-192952 Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 are you trying to do pagination? phpfreaks has tutorials on this Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-192953 Share on other sites More sharing options...
mkosmosports Posted February 24, 2007 Author Share Posted February 24, 2007 Hey, I know there are tutorials here, but what Ive found only covers pagination using mysql queries. Im trying to split the results of an array only, over multiple pages... Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-192957 Share on other sites More sharing options...
mkosmosports Posted February 24, 2007 Author Share Posted February 24, 2007 Im thinking I need to use a for loop rather than foreach...ahh...this is killin me.... Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-192993 Share on other sites More sharing options...
mkosmosports Posted February 24, 2007 Author Share Posted February 24, 2007 jesirose just came in. I could definetely use her brains on this one.... Link to comment https://forums.phpfreaks.com/topic/39877-displaying-foreach-array-results-over-multiple-pages/#findComment-193039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.