Jump to content

Displaying foreach array results over multiple pages..


mkosmosports

Recommended Posts

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..

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>");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.