4images Forum & Community

4images Help / Hilfe => Bug Fixes & Patches => Topic started by: V@no on September 01, 2008, 02:12:24 AM

Title: [1.7 - 1.7.6] Comments count not updated after user was deleted.
Post by: V@no 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.