LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP - Dynamically listing pictures - but only a certain # per page? (https://www.linuxquestions.org/questions/programming-9/php-dynamically-listing-pictures-but-only-a-certain-per-page-563980/)

ziphem 06-23-2007 12:32 PM

PHP - Dynamically listing pictures - but only a certain # per page?
 
Hi! I have a motion activated webcam that takes pictures for a little country house I have. It uploads the pics to my server, sitting in a domain's www directory. I can just visit the website every day to make sure the house hasn't burned down!

Sometimes, when it's windy, there are lots of false alarms, and I get a ton of pictures. Rather than having all of them always displayed on the index page, how can I write the PHP code to show only, say, 30 pictures per page, with the "next page" option, which will then also just show 30 more on that page (and continuing like that for all the pictures)? I have searched online for some coding help, but I just couldn't seem to find instructions or code for what I was looking for.

Thank you for any help!!!

Here's what I have now (please no insults on my inefficient code! Or maybe, comments and suggestions, but not too harsh!) :

Code:


<?php
include("/home/httpd/vhosts/MYDOMAIN.com/httpdocs/upstate/ping_driveway.php");
?>
<br>
<?php
include("/home/httpd/vhosts/MYDOMAIN.com/httpdocs/upstate/ping_den.php");
?>


<?php

$dir = "./";
$dirden = "./den/";
$fd = opendir("$dir");
$fdden = opendir("$dirden");

echo "<hr><hr><b><u><h2>DRIVEWAY</h2></u></b>";

while($entry = readdir($fd)) {
if(eregi(".(exe|zip|jpg)$", $entry)) {
echo "<a href=\"$dir$entry\"><img src=\"$dir$entry\" border=\"0\">" .
"</a>\n";
}
}
closedir($fd);
echo "<br><br><hr><hr><b><u><h2>DEN</h2></u></b>";
while($entryden = readdir($fdden)) {
if(eregi(".(exe|zip|jpg)$", $entryden)) {
echo "<a href=\"$dirden$entryden\"><img src=\"$dirden$entryden\" border=\"0\">" .
"</a>\n";
}
}

closedir($fdden);
?>


nc3b 06-24-2007 05:52 AM

Replace the while with a for. And do it this way.

At the beginning get the offset.
PHP Code:


$start_at
=intval($_GET['start']); 

Don't use readdir, use scandir

This function returns an array of filenames.

PHP Code:


//$filenames=scandir(...);

for($i=$start_at$i<$start_at+30$i++)
{
    
//do stuff,
    
echo($filenames[$i]."<br>"); //or whatever you want to do


And then, a link to the next page.

PHP Code:


$start_at
+=30;
echo(
"<a href='".$_SERVER['PHP_SELF']."?start=$start_at'>Next</a>"



All times are GMT -5. The time now is 04:45 PM.