Author Topic: Next image if it last image in category???  (Read 15624 times)

0 Members and 1 Guest are viewing this topic.

Offline qazew

  • Pre-Newbie
  • Posts: 7
    • View Profile
Next image if it last image in category???
« on: March 02, 2010, 08:26:50 PM »
Sorry for my english, but I am need some modification in the details.php

the metter is that, when in the category I watch the last picture, the next thumb image is empty. how I can do that to me show the next thumb image of next image ID?

For example, I watch last picture in the "Main" category with id=8. In the standart details.php the next image will be empty. But i am need in this case to show thumb of image with id=9 (if such photo is exist).

And show previous image from other cat if in this cat it is first photo

Thank you!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Next image if it last image in category???
« Reply #1 on: March 03, 2010, 12:41:52 AM »
Welcome to 4images forum.

Try this. In details.php find:
unset($image_id_cache);

Insert above:
if (!$in_mode && !$next_image_id)
{
  
$sq1 "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
          FROM "
.IMAGES_TABLE."
          WHERE image_active = 1 AND image_id > 
$image_id
          ORDER BY "
.$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
          LIMIT 1"
;
  if (
$row $site_db->query_firstrow($sq1))
  {
    
$next_image_id $row['image_id'];
    
$next_prev_cache[$next_image_id] = $row;
  }
  
$site_db->free_result();
}


It might show image from the same category, if you don't want that, then replace
          WHERE image_active AND image_id $image_id

With:
          WHERE image_active AND image_id $image_id AND cat_id <> $cat_id
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline qazew

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: Next image if it last image in category???
« Reply #2 on: March 03, 2010, 06:13:50 PM »
Thank you! It work but I am desided to make some changes because your code circeled in the higher subcat. At me work not correct, so I decided to change and select next ID picture. Aslo add previous image if it first in the cat. here the code

Code: [Select]
//-----NEXT IMAGE FROM OTHER CAT -------------
if (!$in_mode && !$next_image_id)
{
  $sq1 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
          FROM ".IMAGES_TABLE."
          WHERE image_active = 1 AND image_id = $image_id+1
          ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
          LIMIT 1";
  if ($row = $site_db->query_firstrow($sq1))
  {
    $next_image_id = $row['image_id'];
    $next_prev_cache[$next_image_id] = $row;
  }
  $site_db->free_result();
}
if (!$in_mode && !$prev_image_id)
{
  $sq2 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
          FROM ".IMAGES_TABLE."
          WHERE image_active = 1 AND image_id = $image_id-1
          ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
          LIMIT 1";
  if ($row = $site_db->query_firstrow($sq2))
  {
    $prev_image_id = $row['image_id'];
    $next_prev_cache[$prev_image_id] = $row;
  }
  $site_db->free_result();
}
//---------END--------------------------------

At me it is work good. When in the cat I watch last image the next image will be ID of current picture+1. I am hope I am made all correct. Can you check the code lines, may be can to correct code the the lines will be less. I am not sure why need to have two similar lines $next_prev_cache[$prev_image_id] = $row;

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: Next image if it last image in category???
« Reply #3 on: March 03, 2010, 08:14:22 PM »
now, try this situation. there are 4 images in one category with ids: 1,2,3,4
in second category there are 3 images with ids: 5,6,7
when you open image 4, it will show next image 5 from another category - good. now delete image 5 and 3. open image 4, it wont show any next images...
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline qazew

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: Next image if it last image in category???
« Reply #4 on: March 04, 2010, 01:20:59 PM »
ok, I am modified the code and finaly get such code:

Code: [Select]
//-----NEXT IMAGE FROM OTHER CAT -------------
if (!$in_mode && !$next_image_id)
{
  $sq1 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
          FROM ".IMAGES_TABLE."
           WHERE image_active = 1 AND cat_id > $cat_id
          ORDER BY cat_id, ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
          LIMIT 1";
  if ($row = $site_db->query_firstrow($sq1))
  {
    $next_image_id = $row['image_id'];
    $next_prev_cache[$next_image_id] = $row;
  }
  $site_db->free_result();
}
if (!$in_mode && !$prev_image_id)
{
  if(substr($config['image_sort'],0,1)=="D") $image_prev_sort="ASC"; else $image_prev_sort="DESC";
  $sq2 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
          FROM ".IMAGES_TABLE."
           WHERE image_active = 1 AND cat_id < $cat_id
          ORDER BY cat_id DESC, ".$config['image_order']." ".$image_prev_sort.", image_id ".$image_prev_sort."
          LIMIT 1";
  if ($row = $site_db->query_firstrow($sq2))
  {
    $prev_image_id = $row['image_id'];
    $next_prev_cache[$prev_image_id] = $row;
  }
  $site_db->free_result();
}
//---------END--------------------------------

in the "Image settings" I have Sort images by Date.

When you reach the last image in the category in next preview, you get next thumbnail image from next category.

Please check. need to work

Offline uploadeur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Next image if it last image in category???
« Reply #5 on: October 05, 2011, 04:51:54 AM »
These codes are great but i want something different: Your code makes next image of the next category but i want first image of the same category. Could you modify that?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Next image if it last image in category???
« Reply #6 on: October 05, 2011, 01:24:04 PM »
Replace
Code: [Select]
          WHERE image_active = 1 AND image_id > $image_id

with:
Code: [Select]
          WHERE image_active = 1 AND cat_id = $cat_id
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline uploadeur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Next image if it last image in category???
« Reply #7 on: October 07, 2011, 11:33:45 PM »
But i cant find this query because i used the qazew's code not yours. So can you look at this?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Next image if it last image in category???
« Reply #8 on: October 08, 2011, 09:36:08 PM »
Then search for
Code: [Select]
WHERE image_active = 1 AND cat_id > $cat_id
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline zimba

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Next image if it last image in category???
« Reply #9 on: October 13, 2011, 10:17:49 PM »
- When i get the last picture it jumps in the same category to the second pic and not the first.

- What i have to add to jump from the first to the last ( << backward) ?

Offline uploadeur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Next image if it last image in category???
« Reply #10 on: November 01, 2011, 06:08:45 AM »
Next button is ok, working very well, but prev. button, if its the first image of the cat. its loading previous category, how can i make load the last image of the same category like next button do.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Next image if it last image in category???
« Reply #11 on: November 01, 2011, 06:42:09 AM »
You got to specify which code you are using.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline uploadeur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Next image if it last image in category???
« Reply #12 on: November 02, 2011, 06:27:50 AM »
i am using qazew's code with your modification.

Offline qazew

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: Next image if it last image in category???
« Reply #13 on: November 09, 2011, 07:24:38 PM »
i am using qazew's code with your modification.

Try to use a Vano's code in the second message. If I am correctly understood you what you want, this code will fine for you