Results 1 to 6 of 6

Thread: can i restrict the code to show one image?

  1. #1
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can i restrict the code to show one image?

    Hey guys

    I am trying to get this script just to show one image, basically at the moment it reads the folder specified as $dir and displays every image in there... how can i restrict the amount of images shown?

    this is above the page
    PHP Code:
    <?php
        $login 
    $_GET['login'];
        
    $NBFile=0;
        
    $dir ="clients/$login";

    if (
    $handle opendir($dir)) {
        while (
    false !== ($file readdir($handle))) {
    if (
    $file != "." && $file != "..") {
        
    $FileArray[] = $dir."/".$file;
        
    $NBFile=$NBFile+1;
    }}}
    closedir($handle);
    ?>
    On the page

    PHP Code:
    <?php
    $NBPicswidth
    =1;
    $NBPics=0;
    for (
    $i=0$i<$NBFile$i++

    {
    $image=$FileArray[$i];

    echo 
    "<img src='$image'>";

    $NBPics=$NBPics+1;
    if ( 
    $NBPics==$NBPicswidth 

    $NBPics=0
    }
    }
    ?>

  2. #2
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, scrub that, ive got it....

    PHP Code:
        $login $_GET['login'];
        
    $NBFile=1//CHANGED THIS FROM =0
        
    $dir ="clients/$login";

    if (
    $handle opendir($dir)) {
        while (
    false !== ($file readdir($handle))) {
    if (
    $file != "." && $file != "..") {
        
    $FileArray[] = $dir."/".$file;
        
    $NBFile=$NBFile//CHANGED THIS FROM $NBFile=$NBFile+1; 

  3. #3
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try this:
    PHP Code:
    <?php
    $NBPicswidth
    =1;
    $NBPics=0;
    for (
    $i=0$i<2$i++

    // replace 2 with the ammount of img
    $image=$FileArray[$i];

    echo 
    "<img src='$image'>";

    $NBPics=$NBPics+1;
    if ( 
    $NBPics==$NBPicswidth 

    $NBPics=0
    }
    }
    ?>
    Jeremy | jfein.net

  4. #4
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Try this:
    PHP Code:
    <?php
    $NBPicswidth
    =1;
    $NBPics=0;
    for (
    $i=0$i<2$i++

    // replace 2 with the ammount of img
    $image=$FileArray[$i];

    echo 
    "<img src='$image'>";

    $NBPics=$NBPics+1;
    if ( 
    $NBPics==$NBPicswidth 

    $NBPics=0
    }
    }
    ?>
    Hey,

    I'm trying to get this to display 10 images at a time, I have assigned a total image variable, and I am using pagination scripting that will allow me next and previous...

    any ideas how i can set this to display 10 images, and assign the start image and end image number?

    basically if i have 500 images I dont want to show all 500 images on the same page.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    But did this script show 2 images? If it did, and you want it to display 10 images, try this:
    PHP Code:
    <?php
    $NBPicswidth
    =1;
    $NBPics=0;
    for (
    $i=0$i<10$i++

    // [ICODE]replace 10 with the ammount of img[/ICODE]
    $image=$FileArray[$i];

    echo 
    "<img src='$image'>";

    $NBPics=$NBPics+1;
    if ( 
    $NBPics==$NBPicswidth 

    $NBPics=0
    }
    }
    ?>
    Jeremy | jfein.net

  6. #6
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I think you're talking about pagination. You use the $_GET super global to retrieve the current "page" the user is on (which is there you start-- (($number_per_page * $current_page) -$number_per_page)), and then advance so many in the array from there. See the tutorial, because I don't think I explained that very well

    An example of how it *might* work in your page:
    Code:
    <?php
    
    $page = (isset($_GET['page'])) ? $_GET['page']: 1;
    
    $limit = 10; //How many per page?
    $limter= ($limit*page) - $limit;
    
    $NBPicswidth=1;
    $NBPics=0;
    
    for ($i=$limiter; $i<$limit; $i++) {
        $image=$FileArray[$i];
        echo "<img src='$image'>";
        $NBPics=$NBPics+1;
    
        if ( $NBPics==$NBPicswidth ) { 
            $NBPics=0; 
        }
    }
    ?>
    Last edited by Jas; 03-17-2008 at 11:39 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •