php - Pagination inside foreach loop
I try create pagination inside loop foreach for show results , the problem no works for me , i create this little script :
foreach ($array as $pag_id=>$array_2)
{
$results_by_page="2";
if ($_REQUEST['page']=="")
{
$pag_ini=0;
$pag_end="$results_by_page";
}
if ($_REQUEST['page']=="0")
{
$pag_ini=0;
$pag_end="$results_by_page";
}
if ($_REQUEST['page']=="1")
{
$pag_ini="".$results_by_page."";
$pag_end="".($results_by_page+$pag_ini)."";
}
if ($_REQUEST['page']>"1")
{
$pag_end="".($_REQUEST['page']*$results_by_page)."";
$pag_ini="".($pag_end-$results_by_page)."";
}
if ($pag_id==$pag_ini && $pag_id<=$pag_end)
{
break;
}
}
I don´t know if it´s possible create paginaton using this loop buy i need use it
With loop for no give me problem do this , but in this case i need use foreach
Also if exists other method for pagination inside this kind of loop you can put here
Thank´s for community the help
Answer
Solution:
If you had it working before with a
for
loop, why not do this:You then can do what you were doing in the
for
loop while keeping the benefits of theforeach
loop.