Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Limit images displayed.
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amailer




PostPosted: Tue Jul 22, 2003 8:51 pm   Post subject: Limit images displayed.

K,

Im not using a database for this so i don't know how to display a limited number of images from a folder?

Suppose i got 10 files in a folder...
i want it to display 5 fils only.

Anyone?
Sponsor
Sponsor
Sponsor
sponsor
PaddyLong




PostPosted: Wed Jul 23, 2003 6:41 pm   Post subject: (No subject)

what I would do is load all the file names into an array then just run a for loop that's like
code:

for($i=0; $i<5; $i++){
print ("<img src=\"directory/".imagearray[$i].".jpg/" other img tags>")
}
Amailer




PostPosted: Wed Jul 23, 2003 6:47 pm   Post subject: (No subject)

ok i got it, but i just got a lil prob..ill ask for help if i need.

BTW thx for helping...:/


EDIT:

k...odd it displays only the top 2 it happned before...AND ITS HAPPNING AGAIN!

k even searched on google...event hey got the same prob...
code:

                if (!is_dir($default_dir)) die("Cannot open images for type: $type");

                if (!($dp = opendir($default_dir))) die("Cannot open $default_dir.");

                while  (FALSE !=($file = readdir($dp)))

                        $file_array[] = $file;

                        for($i=0; $i<5; $i++) {

               
                //if ($file != '.' && $file != '..' && ereg("$type", $file))

echo  "<body></body><center><img border=\"0\" src=\"$default_dir/" . $file_array[$i] . "\"><br><b>File name:</b> $file</center><br><br></html>";
                }
PaddyLong




PostPosted: Thu Jul 24, 2003 11:01 am   Post subject: (No subject)

well... it seems that you are loading into the array the . and .. and I think there's also one other funny little hidden file that's sometimes there it's like thumbs.db or something .... try something... instead of printing the img tag out just print the file name out so you can see what images it's trying to do...

the solution to this would be to put the if statement for !="." etc in your while loop where you load the file names into the array
Amailer




PostPosted: Thu Jul 24, 2003 11:48 am   Post subject: (No subject)

Hmm no,
i got that...thing is that i commented the
code:

if ($file_array[$i] != '.' && $file_array[$i] != '..' && ereg("$type", $file_array[$i]))


Which actually...takes out the files that are not part of the extentions give...hehe :/

so i got it to work

but now....if i put the limit to 5..it will display 3..so to display 5..i need to put the limit to 7 :/

ah well :/
PaddyLong




PostPosted: Fri Jul 25, 2003 2:20 pm   Post subject: (No subject)

it's exactly because of what I said... the first two indexes of your array are in fact the . and .. because you don't have the if statement inside of the loop where you are scanning the directory... all you are doing with the if statement in the for loop is skipping over outputting the img tag for those indexes of the array

make it this, and it should work...

code:

      if (!is_dir($default_dir)) die("Cannot open images for type: $type");

      if (!($dp = opendir($default_dir))) die("Cannot open $default_dir.");

      while  (FALSE !=($file = readdir($dp))){
         if ($file != '.' && $file != '..' && ereg("$type", $file))
         $file_array[] = $file;
      }

      for($i=0; $i<5; $i++) {
         echo  "<body></body><center><img border=\"0\" src=\"$default_dir/" . $file_array[$i] . "\"><br><b>File name:</b> $file</center><br><br></html>";
      }
Amailer




PostPosted: Fri Jul 25, 2003 3:30 pm   Post subject: (No subject)

thx but i did it another way,
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: