Jump to content

Recommended Posts

hi every one thanks for this forum i want help please

i want add pagination to this script and listed the floder by last modification

<table width='100%' border='0'>
<?php
$gr = "music/Musique-Maghreb/";
$gr="music/$cat/";
$rep=opendir($gr);
$c=1;
while ($file = readdir($rep)){
	if($file != '..' && $file !='.' && $file !=''){ 
if (file_exists("images/$file.jpg")) {
$img="images/$file.jpg";
} else {
$img="images/nophoto.jpg";
}
if ($c==1) {
echo "<tr>";
}
?>
<?php echo $file;?>
</tr>
              <TR>
<tr>
    <td>
 
</td>
</tr>
</tbody>
</table><?php
if($c==5) {
echo "</tr>";
$c=0;
}
$c++;
}
}
 
closedir($rep);
clearstatcache();
?>
 
</td>
</center></div>
</table>
Link to comment
https://forums.phpfreaks.com/topic/291009-help-in-pagination-without-mysql/
Share on other sites

the best method would be to put the information into an array, then use array_slice() to reference a specific 'page' of that information. the array_slice() offset and length parameters function exactly the same as a LIMIT clause in a mysql based pagination query.

assuming you have or have written a database based pagination script, it is doing two things. 1) getting a total count of the number of data items, and 2) retrieving the correct 'page' of data to display.

 

to accomplish pagination for an array of data, you would first get all your data into an array, in the order that you want the data. then, to accomplish item #1, you would use count() on the array of data. to accomplish item #2, you would use array_slice() on the array of data, using the offset and length (number of rows per page) values normally going into the LIMIT clause in a database query as the parameters going into the array_slice() statement. you would then loop over the array of data that the array_slice() statement returned to produce the output on the page.

 

to get your array of data ordered the way you want, you can either use php's usort() or array_multisort() statements. examples of using these are in the php.net documentation and posted all over the web.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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