Log in

View Full Version : Resolved New: How do I paginate?



Download
06-22-2010, 08:16 PM
How can I?

<?php

$dir = "thumbs/";
echo "<br /><br /><center>";
//open dir
if ($opendir = opendir($dir))
{
//read dir
while (($file = readdir($opendir)) !== FALSE)
{
if ($file!="."&&$file!="..")
echo "<a href='image.php?id=$file'><div id=\"image\"><img src='thumbs/$file'\ ></div></a>&nbsp;&nbsp;&nbsp;&nbsp;";
}
}
echo "</center>";
?>

I need to paginate the images, how can I?

djr33
06-22-2010, 11:26 PM
Here's the usual method for this:

$d = opendir($d); //open dir
while ($f = readdir($d)) { //get the next file
if ($f=='.'||$f=='..') { continue; } //skip if it's the current or parent directory -- always use this
if (is_dir($d.'/'.$f)) { continue; } //HERE-- skip directories
echo $d.'/'.$f; //path to file. Skip $d if you just want the filename
}

Add the check to be sure is_dir($d) at the top if you want.


'continue' makes the loop skip the rest of that instance and go back to the beginning.

Download
06-23-2010, 12:11 AM
Hey, coincidentally my name is Dan also!

Anyways you weren't fast enough :P
Thanks anyways, rep +1 for you my good man

Download
06-23-2010, 01:53 AM
New topic, can anyone help?

djr33
06-23-2010, 02:04 AM
What? Why did you edit your post? This is confusing for someone else who might have been helped by the previous information/answers.

Feel free to start a new thread if you want to ask a new question, though.

Download
06-23-2010, 02:08 AM
Ok, thanks anyways I have figured this out. If you want you can lock this thread