Author Topic: [1.7 - 1.7.6] Comments count not updated after user was deleted.  (Read 17065 times)

0 Members and 1 Guest are viewing this topic.

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
[1.7 - 1.7.6] Comments count not updated after user was deleted.
« on: September 01, 2008, 02:12:24 AM »
When a user deleted with their comments, the comments count in each image not being updated.

In admin/users.php find:

    if ($delcomments) {


Insert BELOW:

      $sql "SELECT i.image_id, COUNT(c.comment_id) AS count
              FROM " 
IMAGES_TABLE " i
              LEFT JOIN " 
COMMENTS_TABLE " c ON c.image_id = i.image_id
              WHERE c.user_id = " 
$user_id "
              GROUP BY i.image_id"
;
      
$result $site_db->query($sql);
      while(
$row $site_db->fetch_array($result))
      {
        
$sql "UPDATE " IMAGES_TABLE "
                SET image_comments = image_comments - " 
$row['count'] ."
                WHERE image_id = " 
$row['image_id'];
        
$site_db->query($sql);
      }



If your comments count not messed up you don't need do anything else, but for these who's comments count different from actual count you can run this MySQL query in phpmyadmin:
Code: (MySQL) [Select]
UPDATE 4images_images i
SET i.image_comments = (SELECT COUNT(comment_id) FROM 4images_comments WHERE image_id = i.image_id)

If the query above didn't work for you, download attached file, extract update_comments_count.php from the package and upload it to your 4images root directory then run it by typing in your browser: http://yoursiteaddress/4images/update_comments_count.php
After that delete the file.
« Last Edit: February 18, 2009, 08:39:17 AM by V@no »
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)