#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Number of image displayed from an album


    I am trying to number the images in an album that are shown. Currently in my example (under album_view)
    I get the following shown for every image: 1 of 16 (first image), 2 of 16 (second image), 3 of 16 (third image)... 16 of 16 (last image).

    Obviously 1 want to show just 1 of 16 for the first image and then 2 of 16 for the second and so on.

    Cannot find a suitable example for this and I am stuck. Thanks.

    I have the following code:-

    album_view.php: This should give 1 of 16 (example), When on the first image in the album.
    Then 2 of 16, when on the second image and so on
    The last image in the album would be 16 of 16.

    I call a function from another file image.php.

    The following is the code used.

    image.php -

    <?php
    function get_number($artist_id) {
    $artist_id = (int)$artist_id;
    $number = array();

    $number_query = mysql_query("SELECT `image_album_id`, `artist_id`
    FROM `album_images`
    WHERE `artist_id` = $artist_id AND `member_id` =".$_SESSION['member_id']) or die(mysql_error());

    $number_img_row = 1;
    $total_imgs = mysql_num_rows($number_query);

    While ($number_row = mysql_fetch_assoc($number_query)) {
    $number[] = array(
    'image_album_id' => $number_row['image_album_id'],
    'artist_id' => $number_row['artist_id'],
    'image_ord' => $number_img_row,
    'total_imgs' => $total_imgs
    );

    $number_img_row++;
    }
    return $number;
    }

    ?>

    album_view.php -

    <?php
    $number = get_number($artist_id);

    foreach ($number as $imgnumber) {

    echo "<i>".$imgnumber['image_ord']." of ".$imgnumber['total_imgs']."<br />";
    }

    ?>
  2. #2
  3. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Sep 2003
    Location
    Germany
    Posts
    1,355
    Rep Power
    323
    First up, please wrap your code in PHP tags, makes it easier to read (http://forums.devshed.com/php-development-5/please-wrap-php-codes-using-the-php-php-tag-932162.html)

    Second, what exactly is your problem? What doesn't work?
    IkoTikashi - ikotikashi.de
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Hi,

    I want to show 1 of 5 for first image displayed , 2 of 5 for second image displayed and so on until 5 of 5 for last image displayed

    My code gives 1 of 5 2 of 5 3 of 5 4 of 5 5 of 5 for every image displayed.

    Hope that makes it clearer.
  6. #4
  7. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Sep 2003
    Location
    Germany
    Posts
    1,355
    Rep Power
    323
    Does your album_view.php show all of the images in a list/grid view? Or just one image at a time? Your loop in album_view.php should already do what you're after, you'd just need to print out the image with it. Or is this done in another function?
    IkoTikashi - ikotikashi.de
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Ni,

    Only one image is shown at a time.

    The image is shown with the following code:

    PHP Code:
    $image_album_id =$_GET['image_album_id'];
    $image_data image_data($image_album_id'artist_id''album_name''ext''timestamp');
    echo 
    ''
    <a href="album_view.php?artist_id=
    PHP Code:
     echo $curr_id,'&image_album_id=',$image_album_id
    ">
    <img src="
    PHP Code:
     echo 'images/albums/thumbs/'$curr_id.'/'.$image_album_id.'.'.$curr_ext
    " height="175px" width="175px"></a> </td>

    Thanks
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    well, in that case your funktion doesn't really make sense, because it's obviously made for a series of images. I mean, when you fetch all images, loop through them and print out "i of n" every time, then that's what you'll get: "1 of n", "2 of n", ...

    When you only want to display a "i of n" for a single image, then you don't need all images. You just need the total number of images (for the "n") and the number of images before the current one (for the "i"). How exactly the query looks like depends on your exact tables and the numbering scheme. Do you order by some date? By the primary key?

    Currently, you don't order by anything, which is conceptually wrong. You rely on some "random" order chosen by MySQL, which could theoretically change and lead to inconsistent numbering.

    You also need to fix several big security holes:

    Donít insert raw values into query strings.
    Donít output raw values or insert them into the HTML page.
    Donít display internal error messages.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0
    Hi,

    You are saying the reason i get data back for every image (when each image is displayed) is because the code is stating that for
    every image (foreach...) the data is returned. I do understand what you are saying. Also, that it is better to have an "ORDER BY". I have changed the query to reflect this and have put `image_album_id`.

    I get the total number of images ok.

    However, I do not know how to proceed after that, brain is scrambled!!

    The table has the following colums:- image_album_id (primary key), artist_id, member_id, timestamp, album_name.

    Many thanks

IMN logo majestic logo threadwatch logo seochat tools logo