[Solved]: metaalbum: lastcomments [Solved]: metaalbum: lastcomments
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

[Solved]: metaalbum: lastcomments

Started by streetart, September 21, 2008, 07:09:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

streetart

hello

I display on the frontpage 5 last comments. I want display one picture only once. when I have two comments on the same picture, there display the pic twice. How can I turn that off?

thx

streetart

hello

I found this code in a topic

// Mod start: group comments on the same pic
/*
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $TMP_SET $keyword)";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);

                $select_columns = '*'; //allows building any data into any thumbnail caption
                if($select_columns == '*'){
                  $select_columns = 'p.*, msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
                } else {
                  $select_columns = str_replace('pid', 'c.pid', $select_columns).', msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
                }

                $TMP_SET = str_replace($CONFIG['TABLE_PICTURES'],'p',$TMP_SET);
                $query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid $TMP_SET $keyword) ORDER by msg_id DESC $limit";
                $result = cpg_db_query($query);
*/

                $QUERY_META_ALBUM_SET = str_replace( $CONFIG['TABLE_PICTURES'], "p" , $TMP_SET );

$query = "SELECT COUNT(DISTINCT(c.pid)) FROM `cpg148_comments` AS c, `cpg148_pictures` AS p
WHERE p.approved = 'YES' AND c.pid = p.pid $QUERY_META_ALBUM_SET $keyword);";

                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);


                $query = "SELECT p.*, c1.msg_id, c1.author_id, c1.msg_author, c2.msg_date, c1.msg_body, c1.pid
FROM {$CONFIG['TABLE_PICTURES']} as p,
  {$CONFIG['TABLE_COMMENTS']} as c1,
  (SELECT pid, MAX(UNIX_TIMESTAMP(msg_date)) as msg_date
    FROM {$CONFIG['TABLE_COMMENTS']}
    GROUP BY pid
    ORDER BY msg_date DESC) AS c2
WHERE UNIX_TIMESTAMP(c1.msg_date) = c2.msg_date
  AND p.approved = 'YES' AND c1.pid = p.pid
  $QUERY_META_ALBUM_SET $keyword)
GROUP BY p.pid
ORDER BY msg_date DESC
$limit;";
$result = cpg_db_query($query);

// Mod end: group comments on the same pic


but I have a daatebase error

Nibbler

There are some hard coded table prefixes there


$query = "SELECT COUNT(DISTINCT(c.pid)) FROM `cpg148_comments` AS c, `cpg148_pictures` AS p
WHERE p.approved = 'YES' AND c.pid = p.pid $QUERY_META_ALBUM_SET $keyword);";


Change to


$query = "SELECT COUNT(DISTINCT(c.pid)) FROM {$CONFIG['TABLE_COMMENTS']} AS c, {$CONFIG['TABLE_PICTURES']} AS p
WHERE p.approved = 'YES' AND c.pid = p.pid $QUERY_META_ALBUM_SET $keyword);";

streetart

USER:
------------------
Array
(
    [ID] => f6f850bd348661eda2f8d2ed649ed32b
    [am] => 1
    [lang] => german
    [liv] => Array
        (
            [0] => 391
            [1] => 407
            [2] => 385
            [3] => 376
            [4] => 59
        )

    [theme] => k2
    [sort] => ta
    [search] => Array
        (
            [search] => RAS
        )

    [lap] => 1
)

==========================
USER DATA:
------------------
Array
(
    [user_id] => 1
    [user_name] => DaBe
    [groups] => Array
        (
            [0] => 1
        )

    [disk_max] => 0
    [disk_min] => 0
    [can_rate_pictures] => 0
    [can_send_ecards] => 0
    [ufc_max] => 1
    [ufc_min] => 1
    [custom_user_upload] => 0
    [num_file_upload] => 10
    [num_URI_upload] => 0
    [can_post_comments] => 1
    [can_upload_pictures] => 1
    [can_create_albums] => 1
    [has_admin_access] => 1
    [pub_upl_need_approval] => 0
    [priv_upl_need_approval] => 0
    [group_name] => Administrators
    [upload_form_config] => 1
    [group_quota] => 0
    [can_see_all_albums] => 1
    [group_id] => 1
)

==========================
Queries:
------------------
Array
(
    [0] => SELECT extension, mime, content, player FROM cpg54x_filetypes; (0.006s)
    [1] => select * from cpg54x_plugins order by priority asc; (0.001s)
    [2] => SELECT * FROM cpg54x_plugins (0.003s)
    [3] => SELECT * FROM cpg54x_plugin_enlargeit (0.012s)
    [4] => delete from `usr_web619_3`.cpg54x_sessions where time<1222073437 and remember=0; (0.004s)
    [5] => delete from `usr_web619_3`.cpg54x_sessions where time<1220867437; (0.015s)
    [6] => select user_id from `usr_web619_3`.cpg54x_sessions where session_id=md5("ffc92120f34a11da8063360fe9b6e32a6f276fac5a1d8fb8d0f8f73dde590317"); (0.005s)
    [7] => select user_id as id, user_password as password from `usr_web619_3`.cpg54x_users where user_id=1 (0.005s)
    [8] => SELECT u.user_id AS id, u.user_name AS username, u.user_password AS password, u.avatar_url AS avatar_url, u.enable_admin_email AS notify, u.auto_subscribe_post AS auto_subscribe_post, u.auto_subscribe_comment AS auto_subscribe_comment, u.user_group+100 AS group_id FROM `usr_web619_3`.cpg54x_users AS u INNER JOIN `usr_web619_3`.cpg54x_usergroups AS g ON u.user_group=g.group_id WHERE u.user_id='1' (0.02s)
    [9] => SELECT user_group_list FROM `usr_web619_3`.cpg54x_users AS u WHERE user_id='1' and user_group_list <> ''; (0.002s)
    [10] => SELECT MAX(group_quota) as disk_max, MIN(group_quota) as disk_min, MAX(can_rate_pictures) as can_rate_pictures, MAX(can_send_ecards) as can_send_ecards, MAX(upload_form_config) as ufc_max, MIN(upload_form_config) as ufc_min, MAX(custom_user_upload) as custom_user_upload, MAX(num_file_upload) as num_file_upload, MAX(num_URI_upload) as num_URI_upload, MAX(can_post_comments) as can_post_comments, MAX(can_upload_pictures) as can_upload_pictures, MAX(can_create_albums) as can_create_albums, MAX(has_admin_access) as has_admin_access, MIN(pub_upl_need_approval) as pub_upl_need_approval, MIN( priv_upl_need_approval) as  priv_upl_need_approval FROM cpg54x_usergroups WHERE group_id in (1) (0s)
    [11] => SELECT group_name FROM  cpg54x_usergroups WHERE group_id= 1 (0.001s)
    [12] => update `usr_web619_3`.cpg54x_sessions set time='1222077038' where session_id=md5('ffc92120f34a11da8063360fe9b6e32a6f276fac5a1d8fb8d0f8f73dde590317'); (0s)
    [13] => SELECT user_favpics FROM cpg54x_favpics WHERE user_id = 1 (0s)
    [14] => SELECT home,login,my_gallery,upload_pic,album_list,lastup,lastcom,topn,toprated,favpics,search FROM cpg54x_final_extract_config WHERE Group_Id=1 (0s)
    [15] => SELECT name, value FROM cpg54x_config where name REGEXP '^plugin_displayfields_' (0.002s)
    [16] => SHOW TABLES LIKE 'cpg54x_cms_config' (0.009s)
    [17] => SELECT * FROM cpg54x_cms_config (0.001s)
    [18] => DELETE FROM cpg54x_mod_online WHERE last_action < NOW() - INTERVAL 10 MINUTE (0s)
    [19] => REPLACE INTO cpg54x_mod_online (user_id, user_name, user_ip, last_action) VALUES ('1', 'DaBe', '89.217.36.9', NOW()) (0s)
    [20] => SELECT count(*) as count FROM `cpg54x_guestbook_post` (0s)
    [21] => SELECT count(*) FROM  cpg54x_pms WHERE owner=1 (0s)
    [22] => SELECT count(*) FROM  cpg54x_pms WHERE owner=1 AND showed='0' (0s)
    [23] => DELETE FROM cpg54x_banned WHERE expiry < '2008-09-22 11:50:38' (0s)
    [24] => SELECT * FROM cpg54x_banned WHERE (ip_addr='89.217.36.9' OR ip_addr='89.217.36.9' OR user_id=1) AND brute_force=0 (0s)
    [25] => SELECT cid, name, description, thumb FROM cpg54x_categories WHERE parent = ''  ORDER BY pos (0s)
    [26] => SELECT aid FROM cpg54x_albums as a WHERE category>=10000 (0s)
    [27] => SELECT count(*) FROM cpg54x_pictures as p, cpg54x_albums as a WHERE p.aid = a.aid AND approved='YES' AND category >= 10000 (0s)
    [28] => SELECT cid, name, description, thumb FROM cpg54x_categories WHERE parent = '1'  ORDER BY pos (0s)
    [29] => SELECT aid FROM cpg54x_albums as a WHERE category = '0' (0s)
    [30] => SELECT count(*) FROM cpg54x_albums as a WHERE 1 (0s)
    [31] => SELECT count(*) FROM cpg54x_categories WHERE 1 (0s)
    [32] => SELECT count(*) FROM cpg54x_pictures (0s)
    [33] => SELECT sum(hits) FROM cpg54x_pictures (0s)
    [34] => SELECT count(*) FROM cpg54x_comments (0s)
    [35] => SELECT COUNT(*) FROM cpg54x_pictures WHERE approved = 'NO' (0s)
    [36] => SELECT COUNT(*) from cpg54x_pictures WHERE approved = 'YES'  (0s)
    [37] => SELECT * FROM cpg54x_pictures WHERE approved = 'YES'  ORDER BY pid DESC  LIMIT 0 ,54 (0s)
    [38] => SELECT count(*) as count FROM `cpg54x_guestbook_post` (0s)
    [39] => SELECT * FROM cpg54x_fr_messages m INNER JOIN cpg54x_fr_topics t ON m.topic_id = t.topic_id ORDER BY msg_id DESC LIMIT 1 (0s)
    [40] => SELECT * FROM cpg54x_cms WHERE conid='0' AND type='0' ORDER BY cpos (0s)
    [41] => SELECT COUNT(*) from cpg54x_comments, cpg54x_pictures  WHERE approved = 'YES' AND cpg54x_comments.pid = cpg54x_pictures.pid AND (1 ) (0s)
    [42] => SELECT p.*, msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid FROM cpg54x_comments as c, cpg54x_pictures as p WHERE approved = 'YES' AND c.pid = p.pid AND (1 ) ORDER by msg_id DESC  LIMIT 0 ,81 (0s)
    [43] => SELECT count(*) FROM `usr_web619_3`.cpg54x_users WHERE 1 (0s)
    [44] => SELECT COUNT(*) FROM cpg54x_mod_online (0s)
    [45] => SELECT COUNT(*) FROM cpg54x_mod_online WHERE user_id <> 0 (0s)
    [46] => SELECT user_id AS user_id, user_name AS user_name FROM `usr_web619_3`.cpg54x_users ORDER BY user_id DESC LIMIT 1 (0s)
    [47] => SELECT user_id, user_name FROM cpg54x_mod_online WHERE user_id <> 0 (0s)
    [48] => SELECT avatar_url FROM `cpg54x_users` WHERE user_id='1'; (0s)
)

==========================
GET :
------------------
Array
(
)

==========================
POST :
------------------
Array
(
)



sry but they not work. it display pics more times. at top is the debug code...

and here the code which I take in the functions.php after :
"// Regular albums if
((is_numeric($album))) {"

// Mod start: group comments on the same pic
/*
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $TMP_SET $keyword)";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);

                $select_columns = '*'; //allows building any data into any thumbnail caption
                if($select_columns == '*'){
                  $select_columns = 'p.*, msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
                } else {
                  $select_columns = str_replace('pid', 'c.pid', $select_columns).', msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid';
                }

                $TMP_SET = str_replace($CONFIG['TABLE_PICTURES'],'p',$TMP_SET);
                $query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid $TMP_SET $keyword) ORDER by msg_id DESC $limit";
                $result = cpg_db_query($query);
*/

                $QUERY_META_ALBUM_SET = str_replace( $CONFIG['TABLE_PICTURES'], "p" , $TMP_SET );

$query = "SELECT COUNT(DISTINCT(c.pid)) FROM {$CONFIG['TABLE_COMMENTS']} AS c, {$CONFIG['TABLE_PICTURES']} AS p
WHERE p.approved = 'YES' AND c.pid = p.pid $QUERY_META_ALBUM_SET $keyword);";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);


                $query = "SELECT p.*, c1.msg_id, c1.author_id, c1.msg_author, c2.msg_date, c1.msg_body, c1.pid
FROM {$CONFIG['TABLE_PICTURES']} as p,
  {$CONFIG['TABLE_COMMENTS']} as c1,
  (SELECT pid, MAX(UNIX_TIMESTAMP(msg_date)) as msg_date
    FROM {$CONFIG['TABLE_COMMENTS']}
    GROUP BY pid
    ORDER BY msg_date DESC) AS c2
WHERE UNIX_TIMESTAMP(c1.msg_date) = c2.msg_date
  AND p.approved = 'YES' AND c1.pid = p.pid
  $QUERY_META_ALBUM_SET $keyword)
GROUP BY p.pid
ORDER BY msg_date DESC
$limit;";
$result = cpg_db_query($query);

// Mod end: group comments on the

Nibbler

That's the wrong place. You should be modifying the code further down in the 'lastcom' section.

streetart