LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-23-2007, 12:32 PM   #1
ziphem
Member
 
Registered: Feb 2004
Location: US / EU
Distribution: Fedora 18
Posts: 122

Rep: Reputation: 17
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);
?>

Last edited by ziphem; 06-23-2007 at 12:35 PM.
 
Old 06-24-2007, 05:52 AM   #2
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
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>"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Create and edit TAR archives dynamically with PHP and PEAR LXer Syndicated Linux News 0 02-23-2007 09:31 PM
Sendmail & PHP vs. Grey Listing BlandoCal Linux - Software 0 03-25-2006 07:12 PM
Apache/PHP Question on adding modules dynamically nyheat Linux - Software 3 03-15-2006 12:08 AM
php page can't display but download as php file? taiwf Linux - Software 2 03-07-2006 05:57 PM
php dynamically create transparent png j-ray Programming 2 08-29-2004 08:41 AM


All times are GMT -5. The time now is 01:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration