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.. Quote Link to comment 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>"); Quote Link to comment 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... Quote Link to comment 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 Quote Link to comment 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... Quote Link to comment 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.... Quote Link to comment 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.... 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.