Author Topic: show only picture from spezifics categories as random pictures  (Read 24252 times)

0 Members and 1 Guest are viewing this topic.

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
show only picture from spezifics categories as random pictures
« on: September 21, 2005, 06:53:09 PM »
Hi

I want to show only pictures from specifics categories as random pictures. Let's say, I have a category 10 and a category 15, and now I want to show only the pictures which belongs to this two categories as random pictures.

Is that difficult to implement? I'm a "non-coder" and I would be very happy, if somebody can help me.

Thanks
TIMT

Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #1 on: September 22, 2005, 01:59:49 AM »
you can try find in includes/functions.php:
Code: [Select]
$cat_id_sql = get_auth_cat_sql("auth_viewcat", "NOTIN");add after:
Code: [Select]
  $cat_in = array(1,2,3); //list of category ids
Then find two times:
Code: [Select]
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_idreplace both of them with:
Code: [Select]
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id AND i.cat_id IN (".implode(", ", $cat_in).")

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #2 on: September 22, 2005, 09:41:25 PM »
the problem is, that the picutures next to the categories (pictures instead of folders) are not shown anymore.

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: show only picture from spezifics categories as random pictures
« Reply #3 on: September 23, 2005, 12:07:10 AM »
yeah, that method would affect these too...
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 TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #4 on: September 23, 2005, 07:51:23 AM »
is there another method possible?

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #5 on: September 25, 2005, 10:20:46 AM »
that means, I need two different types of random pictures.
One as it works today and one, who shows only pictures from at least one specific category (it would be perfect, if i can define, from which categories) and without information abotu picturename and username.

how can I do that?


Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #6 on: September 25, 2005, 07:01:22 PM »
oh...right...then leave the first instance of
Code: [Select]
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_idintact, change only second instance of that line.

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #7 on: September 25, 2005, 09:04:42 PM »
no, it doesn't work. I get still shown pictures from all categories.

Offline GeXX

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #8 on: September 25, 2005, 09:24:33 PM »
Nice work, if this could work...

I think a good solution would be to deactive categories for random pictures.
Code: [Select]
WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id AND i.cat_id NOT IN (".implode(", ", $cat_in).")
and to configure at the backand->categories->show this category as random

but i have the same prob here. the code works, but for all other categories (there where it should be another picture and not from the random generated category) the randompicture is still not shown.

a solution there?

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: show only picture from spezifics categories as random pictures
« Reply #9 on: September 25, 2005, 10:30:27 PM »
I think a good solution would be to deactive categories for random pictures.
whatever is works for you. for some people is easier remove few categories from the list for others is easier to use only few specific categories...

anyway, as Хyu BAM said in her(?) last reply, the only line should be changed is in this block:
Quote
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id  AND i.cat_id IN (".implode(", ", $cat_in).")
            LIMIT $number, 1";
    $random_image_cache[0] = $site_db->query_firstrow($sql);
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 TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #10 on: September 25, 2005, 10:45:42 PM »
I add

Code: [Select]
$cat_in = array(1,2,3); //list of category ids
and replaced

Code: [Select]
WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id
with

Code: [Select]
WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id  AND i.cat_id IN (".implode(", ", $cat_in).")
in the mentioned block.

But  I get still shown pictures from all categories.

Offline Xyu BAM

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #11 on: September 25, 2005, 11:16:57 PM »
Then you do something wrong. I've checked it on a fresh v1.7.1 and it worked just as planned.

In fact your last reply
But I get still shown pictures from all categories.

Does not match with your first reply:
the problem is, that the picutures next to the categories (pictures instead of folders) are not shown anymore.

Your first reply indicates that the changes worked and also affected category specific random images and your last reply indicates that no visible changes acured and your random image is workign  as default...
So, which your reply is true?

Offline GeXX

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #12 on: September 25, 2005, 11:36:34 PM »
Quote
whatever is works for you. for some people is easier remove few categories from the list for others is easier to use only few specific categories...
right  :wink:

Quote
anyway, as Хyu BAM said in her(?) last reply, the only line should be changed is in this block:
it's not working, same situation. e.g.: i have 10 categories and with this example it works for the categories 1-3, but the most time (7/10) there is no random-image (empty).

Code: [Select]
    $number = ($total_images > 1) ? mt_rand(0, $total_images - 1) : 0;

    $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name".get_user_table_field(", u.", "user_name")."
            FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
            LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
            WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND c.cat_id = i.cat_id AND i.cat_id IN (".implode(", ", $cat_in).")
            LIMIT $number, 1";
    $random_image_cache[0] = $site_db->query_firstrow($sql);

maybe i'm wrong, but what's up with the variable "$number"?
this $number is generated of the total-images. but the value of total-images is lower in combination of filtered categories.

so if i do following and it works good, maybe there is a better solution:

find:
Code: [Select]
mt_srand((double)microtime() * 1000000);

insert before:
Code: [Select]
      $sql = "SELECT COUNT(*) as total_images
              FROM ".IMAGES_TABLE."
              WHERE image_active = 1 AND cat_id NOT IN ($cat_id_sql) AND cat_id IN (".implode(", ", $cat_in).")";
      $row = $site_db->query_firstrow($sql);
      $total_images = $row['total_images'];

this will calculate the real total_images for the filtered random-images.
it was just a test so i hope this will help to solve this problem with a better solution instead this one :roll:  :D

G.

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #13 on: September 28, 2005, 07:12:52 PM »
somebody here who can help GeXX and me?

Thanks!

Offline GeXX

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: show only picture from spezifics categories as random pictures
« Reply #14 on: September 28, 2005, 11:46:58 PM »
i've solved my problem  :lol: :

more here: http://www.4homepages.de/forum/index.php?topic=4259.15