Author Topic: How to Ignore specific Category for random image  (Read 7510 times)

0 Members and 1 Guest are viewing this topic.

Offline zerandib

  • Pre-Newbie
  • Posts: 2
    • View Profile
How to Ignore specific Category for random image
« on: January 17, 2009, 02:23:57 PM »
Hello,

How to Ignore specific Category for random image

Something like this;
Say i have 5 image categories

- Cars Category
- Vans Category
- Ships Category
- Motorcycle Category
- Trucks Category


What i want to do is, display first 4 categories only as the random images
(Random images should generate only from -->  Cars Category, Vans Category, Ships Category, Motorcycle Category)

Random image should not comes from Category 5. (Trucks Category)
Is it possible to some thing like this!


(I have used the random images [MOD] Slideshow as well)


Thanks


Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: How to Ignore specific Category for random image
« Reply #1 on: January 17, 2009, 02:41:38 PM »
hi,

in the includes/functions.php

you can at function get_random_image_cache() {
set which cat_id should not be used for random images..

example:

Code: [Select]
function get_random_image_cache() {
  global $site_db, $cat_cache, $total_images;

  $random_image_cache = array();
  $cat_id_sql = get_auth_cat_sql("auth_viewcat", "NOTIN");

  if (SHOW_RANDOM_CAT_IMAGE) {
    $sql = "SELECT DISTINCT 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), 123) AND c.cat_id = i.cat_id
            ORDER BY RAND()";
    $result = $site_db->query($sql);
    while ($row = $site_db->fetch_array($result)) {
      $random_image_cache[$row['cat_id']] = $row;
    }
  }
  else {
    if (empty($total_images)) {
      $sql = "SELECT COUNT(*) as total_images
              FROM ".IMAGES_TABLE."
              WHERE image_active = 1 AND cat_id NOT IN (($cat_id_sql), 123)";
      $row = $site_db->query_firstrow($sql);
      $total_images = $row['total_images'];
    }
    if (empty($total_images)) {
      return $random_image_cache;
    }
    mt_srand((double)microtime() * 1000000);
    $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), 123) AND c.cat_id = i.cat_id
            LIMIT $number, 1";
    $random_image_cache[0] = $site_db->query_firstrow($sql);
  }
  return $random_image_cache;
}

replace 123 at
Code: [Select]
(($cat_id_sql), 123)with your cat id (3 times)

for the [MOD] Slideshow you should ask in that thread
« Last Edit: January 21, 2009, 10:25:11 AM by Nicky »
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
Re: How to Ignore specific Category for random image
« Reply #2 on: January 19, 2009, 02:41:46 AM »
Hi,

I'm not having luck with this working for me. Mainly, I want certain categories where members can view the images to be blocked. I tried the same input as above for just one category, but they are still showing up for those who are no registered. I have the string of code below. Also, I'm wondering how exactly you make it for multiple categories. Do you just separate them by commas like "(($cat_id_sql), 22, 18, 13)"??? Something like that?

Code: [Select]
WHERE i.image_active = 1 AND i.cat_id NOT IN (($cat_id_sql), 22) AND c.cat_id = i.cat_id
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: How to Ignore specific Category for random image
« Reply #3 on: January 19, 2009, 08:11:21 AM »
hi Anarchology,

(($cat_id_sql), 123)
you have 3 times in the query ;)
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
Re: How to Ignore specific Category for random image
« Reply #4 on: January 19, 2009, 08:29:59 AM »
hi Anarchology,

(($cat_id_sql), 123)
you have 3 times in the query ;)


Haha! Yes sir, you got me to feel stupid again. I didn't even think to look. I have made the proper changes, and it works like a charm! However (unrelated to this mod), my functions.php seems to have multiple errors when trying to search. I posted that issue in another thread.

As one annoying error is fixed, there always seems to be another 50 to be done, am I right? 8)
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: How to Ignore specific Category for random image
« Reply #5 on: January 19, 2009, 08:38:58 AM »
well, get MOD per MOD correct working ;)

tip:
implement one 1 MOD.
test as unlogged and logged user.. no errors?
next one, and so on.
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Anarchology

  • Jr. Member
  • **
  • Posts: 60
  • I LULZ too much!
    • View Profile
    • Tainted Pix
Re: How to Ignore specific Category for random image
« Reply #6 on: January 19, 2009, 10:24:56 AM »
well, get MOD per MOD correct working ;)

tip:
implement one 1 MOD.
test as unlogged and logged user.. no errors?
next one, and so on.

Yes sir,

I will probably devote tomorrow night to addressing this problem. Along with this, I have submitted a ticked to my service provider (Lunar Pages) to maybe figure out the problem when it comes to the MySQL error showing up under DB in 4Images. The DB error is pointing to my SMF Forum MySQL DB. It's posted below. I'm running around in circles, but I know between the help from this site, smf, and my web server it should all be worked out... well, that and some beer and time! :lol:

The DB error I'm getting in the 4images area:
Code: [Select]
DB Error: Bad SQL Query: SHOW TABLE STATUS FROM `sayyo1_smf5`
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.smf_settings' at line 2
n/a
A personal THANK YOU to all of the great programmers on this site for helping me get my site from something basic to what it is today!

My site: http://taintedpix.com
(warning: some adult content)

Offline Sebas Bonito

  • Sr. Member
  • ****
  • Posts: 271
  • Sebas Bonito
    • View Profile
Re: How to Ignore specific Category for random image
« Reply #7 on: July 07, 2009, 01:17:04 PM »
Doesn't work on my site.
I'd like to the same... some categories should be shown, and some not.