summary refs log tree commit diff stats
path: root/includes/footer.php
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-05 21:48:01 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-05 21:48:01 -0500
commit1cb945e201704062e9940f327464f4b31a861f20 (patch)
treee2e8ddc9d4681c605621ed1132168cdb7b9eb93b /includes/footer.php
parent9ba37f4643f825052c002bda16884ccc73f57ebc (diff)
downloadfourisland-1cb945e201704062e9940f327464f4b31a861f20.tar.gz
fourisland-1cb945e201704062e9940f327464f4b31a861f20.tar.bz2
fourisland-1cb945e201704062e9940f327464f4b31a861f20.zip
Changed comments' user index
Previously, the comments table referenced users by username. However, if user ever changed their username, everything would become messed up. To fix
this, the index has been changed to the user ID. This change obviously requires maintenance:

This SQL must be run: "ALTER TABLE `comments` ADD `user_id` INT( 11 ) NOT NULL AFTER `page_id`;"

This PHP will generate some SQL that must be run:

<?php

$getusers = "SELECT DISTINCT username FROM comments WHERE is_anon = 0";
$getusers2 = mysql_query($getusers);
while ($getusers3 = mysql_fetch_array($getusers2))
{
        $getuser = "SELECT * FROM phpbb_users WHERE username = \"" . $getusers3['username'] . "\"";
        $getuser2 = mysql_query($getuser);
        $getuser3 = mysql_fetch_array($getuser2);

        echo("UPDATE comments SET user_id = " . $getuser3['user_id'] . " WHERE username = \"" . $getuser3['username'] . "\" AND is_anon = 0;<BR>");
}

$getusers = "SELECT * FROM anon_commenters";
$getusers2 = mysql_query($getusers);
while ($getusers3 = mysql_fetch_array($getusers2))
{
        echo("UPDATE comments SET user_id = " . $getusers3['id'] . " WHERE username = \"" . $getusers3['username'] . "\" AND is_anon = 1;<BR>");
}

?>

This SQL must be run: "ALTER TABLE `comments` DROP `username`;"
Diffstat (limited to 'includes/footer.php')
-rwxr-xr-xincludes/footer.php12
1 files changed, 6 insertions, 6 deletions
diff --git a/includes/footer.php b/includes/footer.php index 77d161b..a37b438 100755 --- a/includes/footer.php +++ b/includes/footer.php
@@ -95,7 +95,7 @@ if (!isset($noRightbar))
95 { 95 {
96 if ($getcomments3[$i]['is_anon'] == 0) 96 if ($getcomments3[$i]['is_anon'] == 0)
97 { 97 {
98 $getuser = "SELECT * FROM phpbb_users WHERE username = \"" . $getcomments3[$i]['username'] . "\""; 98 $getuser = "SELECT * FROM phpbb_users WHERE user_id = " . $getcomments3[$i]['user_id'];
99 $getuser2 = mysql_query($getuser); 99 $getuser2 = mysql_query($getuser);
100 $getuser3 = mysql_fetch_array($getuser2); 100 $getuser3 = mysql_fetch_array($getuser2);
101 101
@@ -103,11 +103,11 @@ if (!isset($noRightbar))
103 $website = $getuser3['user_website']; 103 $website = $getuser3['user_website'];
104 } else if ($getcomments3[$i]['is_anon'] == 1) 104 } else if ($getcomments3[$i]['is_anon'] == 1)
105 { 105 {
106 $getanon = "SELECT * FROM anon_commenters WHERE username = \"" . $getcomments3[$i]['username'] . "\""; 106 $getanon = "SELECT * FROM anon_commenters WHERE id = " . $getcomments3[$i]['user_id'];
107 $getanon2 = mysql_query($getanon); 107 $getanon2 = mysql_query($getanon);
108 $getanon3 = mysql_fetch_array($getanon2); 108 $getanon3 = mysql_fetch_array($getanon2);
109 109
110 if ($getanon3['username'] == $getcomments3[$i]['username']) 110 if ($getanon3['id'] == $getcomments3[$i]['user_id'])
111 { 111 {
112 $username = $getanon3['username'] . ' (Guest)'; 112 $username = $getanon3['username'] . ' (Guest)';
113 $website = $getanon3['website']; 113 $website = $getanon3['website'];
@@ -142,16 +142,16 @@ if (!isset($noRightbar))
142 } 142 }
143 143
144 $users = array(); 144 $users = array();
145 $getusers = "SELECT DISTINCT username FROM comments WHERE is_anon = 0"; 145 $getusers = "SELECT DISTINCT user_id FROM comments WHERE is_anon = 0";
146 $getusers2 = mysql_query($getusers); 146 $getusers2 = mysql_query($getusers);
147 $i=0; 147 $i=0;
148 while ($getusers3[$i] = mysql_fetch_array($getusers2)) 148 while ($getusers3[$i] = mysql_fetch_array($getusers2))
149 { 149 {
150 $getcount = "SELECT COUNT(*) FROM comments WHERE username = \"" . $getusers3[$i]['username'] . "\""; 150 $getcount = "SELECT COUNT(*) FROM comments WHERE user_id = " . $getusers3[$i]['user_id'];
151 $getcount2 = mysql_query($getcount); 151 $getcount2 = mysql_query($getcount);
152 $getcount3 = mysql_fetch_array($getcount2); 152 $getcount3 = mysql_fetch_array($getcount2);
153 153
154 $getuser = "SELECT * FROM phpbb_users WHERE username = \"" . $getusers3[$i]['username'] . "\""; 154 $getuser = "SELECT * FROM phpbb_users WHERE user_id = " . $getusers3[$i]['user_id'];
155 $getuser2 = mysql_query($getuser); 155 $getuser2 = mysql_query($getuser);
156 $getuser3 = mysql_fetch_array($getuser2); 156 $getuser3 = mysql_fetch_array($getuser2);
157 157