Hello, I currently have a php page set up that grabs filenames from a directory and stores them into an array so that i can sort them alphabetically and then display. This works fine. However, i need to now be able to split the array into chunks of 12 and display them on seperate pages automatically adding next and previous pages. Surely it cant be that hard but i just cant get it to work. Please help! Thanks in advance.
well i was gonna sugest using array_slice to split the arrays but this late at night my head just doesnt seem to want to work function keeps failing
OKay it got the better of me hopefully you can work with this //Quick Debug function pre($x){ echo "<pre>"; print_r($x); echo "</pre>"; } $my_array=array("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""); $x=0; //Inital Offset for count $i=1; //Inital Page Number //display if(isset($_GET['offset'])){ echo "Page Display"; //Your display function here pre(array_slice($my_array,$_GET['offset'],12,true)); echo "End display"; } //Pagation echo "<br />pages"; while($x <count($my_array)){ //pre(array_slice($my_array,$x,12,true)); echo "<a href='?offset=$x'>[page$i]</a>"; $x=$x+12; //Increase by array block req $i++; //Increase page # } PHP:
What version of php are you using? The preserve keys option in the array slice function has only been available since PHP 5.0.2 Getting rid of the true value it seems to work fine for me and if I switch to PHP 5 it works fine with the TRUE value.
I followed the tutorial below and was able to make my website paginate and have the previous and next links, and I am an absolute beginner. It was a very helpful tutorial http://www.phpfreaks.com/tutorials/73/0.php
Thanks for the replies and help but i still cant figure it out. If anyone would be willing to help me, PM me and i can send you code or chat on msn. $5 up for grabs.