Author Topic: Selected images in one Category  (Read 3216 times)

0 Members and 1 Guest are viewing this topic.

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Selected images in one Category
« on: September 21, 2008, 01:42:16 PM »
Hi,
     I have created one category and I need to show all the images in this category from all other categories where the description of the images  matches to "xyz"

Can anyone tell me how can I do this ?


To achieve this I have done the following changes in category.php and its working ..Its retrieving all the images correctly from other categories but the count of those images and paging is not correct .. Its still displaying the total images of the original category.

Existing code :

Code: [Select]
$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".$additional_sql.", 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 = $cat_id AND c.cat_id = i.cat_id
        ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT $offset, $perpage";


New code:
Code: [Select]
if ($cat_id == 55) {

$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".$additional_sql.", 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.image_description like '%xyz%' and c.cat_id = i.cat_id
        ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT $offset, $perpage";
} else {
$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".$additional_sql.", 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 = $cat_id AND c.cat_id = i.cat_id
        ORDER BY ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
        LIMIT $offset, $perpage";
}


Is there any other place I am missing to make changes ??

Thanks,
« Last Edit: September 21, 2008, 02:01:20 PM by batu544 »

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: Selected images in one Category
« Reply #1 on: September 21, 2008, 05:17:42 PM »
Try this:
Find:
$num_rows_all = (isset($cat_cache[$cat_id]['num_images'])) ? $cat_cache[$cat_id]['num_images'] : 0;


Insert below:

if ($cat_id == 55)
{
  
$sql "SELECT COUNT (image_id) AS num
          FROM "
.IMAGES_TABLE."
          WHERE image_active = 1 AND image_description like '%xyz%'"
;
  
$result $site_db->query($sql);
  
$num_rows_all $result['num'];
}
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 batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: Selected images in one Category
« Reply #2 on: September 21, 2008, 07:14:02 PM »
Thanks V@no,
                     Simply great !!!!  :)  It worked ..   but I did one change then it worked ..

Code: [Select]
$result = $site_db->query($sql);   to
Code: [Select]
$result = $site_db->query_firstrow($sql);
( I have no idea on php, I don't know technically what is the difference between these ..  :) .. but it worked ) ..


Again Thanks... V@no !!!