diff --git a/classes/donations.class.php b/classes/donations.class.php
index 398016e7..7e68453c 100644
--- a/classes/donations.class.php
+++ b/classes/donations.class.php
@@ -627,7 +627,7 @@ public static function get_leaderboard_position($UserID) {
SELECT Position
FROM (
SELECT d.UserID, @RowNum := @RowNum + 1 AS Position
- FROM users_donor_ranks d
+ FROM users_donor_ranks AS d
ORDER BY TotalRank DESC
) l
WHERE UserID = '$UserID'");
diff --git a/classes/forums.class.php b/classes/forums.class.php
index aebb5556..7be3cbb9 100644
--- a/classes/forums.class.php
+++ b/classes/forums.class.php
@@ -47,7 +47,7 @@ public static function get_thread_info($ThreadID, $Return = true, $SelectiveCach
p.EditedUserID,
p.EditedTime,
ed.Username
- FROM forums_posts as p
+ FROM forums_posts AS p
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
WHERE p.TopicID = '$ThreadID'
AND p.ID = '" . $ThreadInfo['StickyPostID'] . "'");
@@ -169,7 +169,7 @@ public static function get_forums() {
t.IsSticky AS Sticky
FROM forums AS f
JOIN forums_categories AS fc ON fc.ID = f.CategoryID
- LEFT JOIN forums_topics as t ON t.ID = f.LastPostTopicID
+ LEFT JOIN forums_topics AS t ON t.ID = f.LastPostTopicID
GROUP BY f.ID
ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
$Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
@@ -234,15 +234,15 @@ public static function get_last_read($Forums) {
CEIL(
(
SELECT
- COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = l.TopicID
- AND forums_posts.ID<=l.PostID
+ COUNT(p.ID)
+ FROM forums_posts AS p
+ WHERE p.TopicID = l.TopicID
+ AND p.ID <= l.PostID
)/$PerPage
) AS Page
FROM forums_last_read_topics AS l
- WHERE TopicID IN(" . implode(',', $TopicIDs) . ") AND
- UserID='" . G::$LoggedUser['ID'] . "'");
+ WHERE l.TopicID IN(" . implode(',', $TopicIDs) . ") AND
+ l.UserID='" . G::$LoggedUser['ID'] . "'");
$LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
G::$DB->set_query_id($QueryID);
} else {
diff --git a/classes/misc.class.php b/classes/misc.class.php
index 2644d06f..cbb626ad 100644
--- a/classes/misc.class.php
+++ b/classes/misc.class.php
@@ -207,9 +207,9 @@ public static function create_thread($ForumID, $AuthorID, $Title, $PostBody) {
array_pop($Forum);
}
G::$DB->query("
- SELECT f.IsLocked, f.IsSticky, f.NumPosts
- FROM forums_topics AS f
- WHERE f.ID ='$TopicID'");
+ SELECT IsLocked, IsSticky, NumPosts
+ FROM forums_topics
+ WHERE ID ='$TopicID'");
list($IsLocked, $IsSticky, $NumPosts) = G::$DB->next_record();
$Part1 = array_slice($Forum, 0, $Stickies, true); //Stickys
$Part2 = array(
diff --git a/classes/notificationsmanager.class.php b/classes/notificationsmanager.class.php
index ddc161d3..74d01a32 100644
--- a/classes/notificationsmanager.class.php
+++ b/classes/notificationsmanager.class.php
@@ -387,9 +387,9 @@ public function load_collage_subscriptions() {
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT COUNT(DISTINCT s.CollageID)
- FROM users_collage_subs as s
- JOIN collages as c ON s.CollageID = c.ID
- JOIN collages_torrents as ct on ct.CollageID = c.ID
+ FROM users_collage_subs AS s
+ JOIN collages AS c ON s.CollageID = c.ID
+ JOIN collages_torrents AS ct ON ct.CollageID = c.ID
WHERE s.UserID = " . G::$LoggedUser['ID'] . "
AND ct.AddedOn > s.LastVisit
AND c.Deleted = '0'");
diff --git a/classes/permissions.class.php b/classes/permissions.class.php
index ca9113ea..833b32be 100644
--- a/classes/permissions.class.php
+++ b/classes/permissions.class.php
@@ -26,8 +26,8 @@ public static function get_permissions($PermissionID) {
if (empty($Permission)) {
$QueryID = G::$DB->get_query_id();
G::$DB->query("
- SELECT p.Level AS Class, p.Values as Permissions, p.Secondary, p.PermittedForums
- FROM permissions AS p
+ SELECT Level AS Class, `Values` AS Permissions, Secondary, PermittedForums
+ FROM permissions
WHERE ID='$PermissionID'");
$Permission = G::$DB->next_record(MYSQLI_ASSOC, array('Permissions'));
G::$DB->set_query_id($QueryID);
@@ -53,9 +53,9 @@ public static function get_permissions_for_user($UserID, $CustomPermissions = fa
if ($CustomPermissions === false) {
$QueryID = G::$DB->get_query_id();
G::$DB->query('
- SELECT um.CustomPermissions
- FROM users_main AS um
- WHERE um.ID = '.((int)$UserID));
+ SELECT CustomPermissions
+ FROM users_main
+ WHERE ID = ' . (int)$UserID);
list($CustomPermissions) = G::$DB->next_record(MYSQLI_NUM, false);
G::$DB->set_query_id($QueryID);
}
diff --git a/classes/requests.class.php b/classes/requests.class.php
index 610b415f..75f43ab3 100644
--- a/classes/requests.class.php
+++ b/classes/requests.class.php
@@ -205,7 +205,7 @@ public static function get_votes_array($RequestID) {
rv.UserID,
rv.Bounty,
u.Username
- FROM requests_votes as rv
+ FROM requests_votes AS rv
LEFT JOIN users_main AS u ON u.ID = rv.UserID
WHERE rv.RequestID = $RequestID
ORDER BY rv.Bounty DESC");
diff --git a/classes/torrents.class.php b/classes/torrents.class.php
index 83266cba..bd50b746 100644
--- a/classes/torrents.class.php
+++ b/classes/torrents.class.php
@@ -80,9 +80,9 @@ public static function get_groups($GroupIDs, $Return = true, $GetArtists = true,
$QueryID = G::$DB->get_query_id();
G::$DB->query("
SELECT
- g.ID, g.Name, g.Year, g.RecordLabel, g.CatalogueNumber, g.TagList, g.ReleaseType, g.VanityHouse, g.WikiImage, g.CategoryID
- FROM torrents_group AS g
- WHERE g.ID IN ($IDs)");
+ ID, Name, Year, RecordLabel, CatalogueNumber, TagList, ReleaseType, VanityHouse, WikiImage, CategoryID
+ FROM torrents_group
+ WHERE ID IN ($IDs)");
while ($Group = G::$DB->next_record(MYSQLI_ASSOC, true)) {
$NotFound[$Group['ID']] = $Group;
@@ -98,7 +98,7 @@ public static function get_groups($GroupIDs, $Return = true, $GetArtists = true,
ID, GroupID, Media, Format, Encoding, RemasterYear, Remastered, RemasterTitle,
RemasterRecordLabel, RemasterCatalogueNumber, Scene, HasLog, HasCue, LogScore,
FileCount, FreeTorrent, Size, Leechers, Seeders, Snatched, Time, ID AS HasFile
- FROM torrents AS t
+ FROM torrents
WHERE GroupID IN ($IDs)
ORDER BY GroupID, Remastered, (RemasterYear != 0) DESC, RemasterYear, RemasterTitle,
RemasterRecordLabel, RemasterCatalogueNumber, Media, Format, Encoding, ID");
@@ -399,14 +399,14 @@ public static function delete_group($GroupID) {
// Get a count of how many groups or requests use the artist ID
G::$DB->query("
SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
+ FROM artists_group AS ag
LEFT JOIN requests_artists AS ra ON ag.ArtistID = ra.ArtistID
WHERE ra.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
list($ReqCount) = G::$DB->next_record();
G::$DB->query("
SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
+ FROM artists_group AS ag
LEFT JOIN torrents_artists AS ta ON ag.ArtistID = ta.ArtistID
WHERE ta.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
diff --git a/classes/wiki.class.php b/classes/wiki.class.php
index 64761385..10a193dd 100644
--- a/classes/wiki.class.php
+++ b/classes/wiki.class.php
@@ -41,8 +41,8 @@ public static function revision_history($Table = '', $PageID = 0, $BaseURL = '')
Summary,
Time,
UserID
- FROM $Table AS wiki
- WHERE wiki.PageID = $PageID
+ FROM $Table
+ WHERE PageID = $PageID
ORDER BY RevisionID DESC");
?>
diff --git a/docs/CodingStandards.txt b/docs/CodingStandards.txt
index 0b8d6393..8c5d9d5d 100644
--- a/docs/CodingStandards.txt
+++ b/docs/CodingStandards.txt
@@ -120,6 +120,12 @@ Long SQL queries shall be separated on multiple lines.
Short SQL queries may be on a single line.
+All SQL keywords shall be uppercase.
+
+Aliases shall be used to refer to any columns whenever multiple tables are
+joined in an SQL query. They shall be using the `tbl_name AS alias_name`
+syntax. No table aliases shall be used for single-table queries.
+
The primary SQL keywords should be at the same indentation level unless
part of a JOIN or other complex statement.
@@ -128,7 +134,7 @@ Use indents as appropriate to aid readability.
The SQL keywords `JOIN`, `RIGHT JOIN`, `LEFT JOIN` must be indented once from
the `SELECT` statement.
-The SQL keyword `AND` must be indented once from the `WHILE` (and similar)
+The SQL keyword `AND` must be indented once from the `WHERE` (and similar)
statements.
The "not equal to" operator `!=` must be used instead of the alternative
diff --git a/sections/ajax/forum/forum.php b/sections/ajax/forum/forum.php
index e44eaefd..8e185972 100644
--- a/sections/ajax/forum/forum.php
+++ b/sections/ajax/forum/forum.php
@@ -39,18 +39,18 @@
if (!isset($Forum) || !is_array($Forum)) {
$DB->query("
SELECT
- t.ID,
- t.Title,
- t.AuthorID,
- t.IsLocked,
- t.IsSticky,
- t.NumPosts,
- t.LastPostID,
- t.LastPostTime,
- t.LastPostAuthorID
- FROM forums_topics AS t
- WHERE t.ForumID = '$ForumID'
- ORDER BY t.IsSticky DESC, t.LastPostTime DESC
+ ID,
+ Title,
+ AuthorID,
+ IsLocked,
+ IsSticky,
+ NumPosts,
+ LastPostID,
+ LastPostTime,
+ LastPostAuthorID
+ FROM forums_topics
+ WHERE ForumID = '$ForumID'
+ ORDER BY IsSticky DESC, LastPostTime DESC
LIMIT $Limit"); // Can be cached until someone makes a new post
$Forum = $DB->to_array('ID',MYSQLI_ASSOC, false);
if ($Page == 1) {
@@ -106,15 +106,15 @@
l.PostID,
CEIL(
(
- SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = l.TopicID
- AND forums_posts.ID <= l.PostID
+ SELECT COUNT(p.ID)
+ FROM forums_posts AS p
+ WHERE p.TopicID = l.TopicID
+ AND p.ID <= l.PostID
) / $PerPage
) AS Page
FROM forums_last_read_topics AS l
- WHERE TopicID IN(".implode(', ', array_keys($Forum)).')
- AND UserID = \''.$LoggedUser['ID'].'\'');
+ WHERE l.TopicID IN(".implode(', ', array_keys($Forum)).')
+ AND l.UserID = \''.$LoggedUser['ID'].'\'');
// Turns the result set into a multi-dimensional array, with
// forums_last_read_topics.TopicID as the key.
diff --git a/sections/ajax/forum/main.php b/sections/ajax/forum/main.php
index 09c8e8ae..fcfa1fec 100644
--- a/sections/ajax/forum/main.php
+++ b/sections/ajax/forum/main.php
@@ -20,13 +20,17 @@
SELECT
l.TopicID,
l.PostID,
- CEIL(( SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = l.TopicID
- AND forums_posts.ID <= l.PostID) / $PerPage) AS Page
+ CEIL(
+ (
+ SELECT COUNT(p.ID)
+ FROM forums_posts AS p
+ WHERE p.TopicID = l.TopicID
+ AND p.ID <= l.PostID
+ ) / $PerPage
+ ) AS Page
FROM forums_last_read_topics AS l
- WHERE TopicID IN(".implode(',', $TopicIDs).")
- AND UserID='$LoggedUser[ID]'");
+ WHERE l.TopicID IN(".implode(',', $TopicIDs).")
+ AND l.UserID='$LoggedUser[ID]'");
$LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
} else {
$LastRead = array();
diff --git a/sections/ajax/forum/thread.php b/sections/ajax/forum/thread.php
index 2b646c48..382233a3 100644
--- a/sections/ajax/forum/thread.php
+++ b/sections/ajax/forum/thread.php
@@ -96,7 +96,7 @@
p.Body,
p.EditedUserID,
p.EditedTime
- FROM forums_posts as p
+ FROM forums_posts AS p
WHERE p.TopicID = '$ThreadID'
AND p.ID != '".$ThreadInfo['StickyPostID']."'
LIMIT $CatalogueLimit");
diff --git a/sections/ajax/inbox/viewconv.php b/sections/ajax/inbox/viewconv.php
index b9073801..a3244a45 100644
--- a/sections/ajax/inbox/viewconv.php
+++ b/sections/ajax/inbox/viewconv.php
@@ -75,7 +75,7 @@
// Get messages
$DB->query("
SELECT SentDate, SenderID, Body, ID
- FROM pm_messages AS m
+ FROM pm_messages
WHERE ConvID = '$ConvID'
ORDER BY ID");
diff --git a/sections/ajax/user.php b/sections/ajax/user.php
index 2a2231b7..93072fe0 100644
--- a/sections/ajax/user.php
+++ b/sections/ajax/user.php
@@ -94,9 +94,9 @@ function check_paranoia_here($Setting) {
WHERE r.FillerID = $UserID");
list($RequestsFilled, $TotalBounty) = $DB->next_record();
$DB->query("
- SELECT COUNT(rv.RequestID), SUM(rv.Bounty)
- FROM requests_votes AS rv
- WHERE rv.UserID = $UserID");
+ SELECT COUNT(RequestID), SUM(Bounty)
+ FROM requests_votes
+ WHERE UserID = $UserID");
list($RequestsVoted, $TotalSpent) = $DB->next_record();
$DB->query("
@@ -120,9 +120,9 @@ function check_paranoia_here($Setting) {
if (check_paranoia_here('artistsadded')) {
$DB->query("
- SELECT COUNT(ta.ArtistID)
- FROM torrents_artists AS ta
- WHERE ta.UserID = $UserID");
+ SELECT COUNT(ArtistID)
+ FROM torrents_artists
+ WHERE UserID = $UserID");
list($ArtistsAdded) = $DB->next_record();
} else {
$ArtistsAdded = 0;
@@ -204,10 +204,10 @@ function check_paranoia_here($Setting) {
if (check_paranoia_here(array('collagecontribs', 'collagecontribs+'))) {
$DB->query("
- SELECT COUNT(DISTINCT CollageID)
+ SELECT COUNT(DISTINCT ct.CollageID)
FROM collages_torrents AS ct
- JOIN collages ON CollageID = ID
- WHERE Deleted = '0'
+ JOIN collages AS c ON ct.CollageID = c.ID
+ WHERE c.Deleted = '0'
AND ct.UserID = '$UserID'");
list($NumCollageContribs) = $DB->next_record();
}
diff --git a/sections/ajax/userhistory/post_history.php b/sections/ajax/userhistory/post_history.php
index b5f1fb6c..3654b95f 100644
--- a/sections/ajax/userhistory/post_history.php
+++ b/sections/ajax/userhistory/post_history.php
@@ -84,7 +84,7 @@ function error_out($reason = '') {
l.PostID AS LastRead,
t.IsLocked,
t.IsSticky
- FROM forums_posts as p
+ FROM forums_posts AS p
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
@@ -122,7 +122,7 @@ function error_out($reason = '') {
$SQL .= "
t.IsLocked,
t.IsSticky
- FROM forums_posts as p
+ FROM forums_posts AS p
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
diff --git a/sections/artist/add_similar.php b/sections/artist/add_similar.php
index 05aa250c..566d56c2 100644
--- a/sections/artist/add_similar.php
+++ b/sections/artist/add_similar.php
@@ -14,9 +14,9 @@
}
$DB->query("
- SELECT ag.ArtistID
- FROM artists_group AS ag
- WHERE ag.Name LIKE '$Artist2Name'");
+ SELECT ArtistID
+ FROM artists_group
+ WHERE Name LIKE '$Artist2Name'");
list($Artist2ID) = $DB->next_record();
if (!empty($Artist2ID)) { // artist was found in the database
@@ -25,7 +25,7 @@
$DB->query("
SELECT s1.SimilarID
FROM artists_similar AS s1
- JOIN artists_similar AS s2 ON s1.SimilarID = s2.SimilarID
+ JOIN artists_similar AS s2 ON s1.SimilarID = s2.SimilarID
WHERE s1.ArtistID = '$Artist1ID'
AND s2.ArtistID = '$Artist2ID'");
list($SimilarID) = $DB->next_record();
diff --git a/sections/better/files.php b/sections/better/files.php
index 5f79b8af..58fee069 100644
--- a/sections/better/files.php
+++ b/sections/better/files.php
@@ -17,7 +17,7 @@
$Join = '';
$All = true;
} else {
- $Join = 'JOIN xbt_snatched as x ON x.fid = tfi.TorrentID AND x.uid = '.$LoggedUser['ID'];
+ $Join = 'JOIN xbt_snatched AS x ON x.fid = tfi.TorrentID AND x.uid = '.$LoggedUser['ID'];
$All = false;
}
diff --git a/sections/better/folders.php b/sections/better/folders.php
index 0f50fa70..551da465 100644
--- a/sections/better/folders.php
+++ b/sections/better/folders.php
@@ -17,7 +17,7 @@
$Join = '';
$All = true;
} else {
- $Join = "JOIN xbt_snatched as x ON x.fid = tbf.TorrentID AND x.uid = ".$LoggedUser['ID'];
+ $Join = "JOIN xbt_snatched AS x ON x.fid = tbf.TorrentID AND x.uid = ".$LoggedUser['ID'];
$All = false;
}
diff --git a/sections/better/snatch.php b/sections/better/snatch.php
index d8b96bde..ddea9b35 100644
--- a/sections/better/snatch.php
+++ b/sections/better/snatch.php
@@ -46,16 +46,16 @@
$DB->query("
CREATE TEMPORARY TABLE temp_sections_better_snatch
SELECT
- t.GroupID,
- GROUP_CONCAT(t.Encoding SEPARATOR ' ') AS EncodingList,
+ GroupID,
+ GROUP_CONCAT(Encoding SEPARATOR ' ') AS EncodingList,
CRC32(CONCAT_WS(
' ', Media, Remasteryear, Remastertitle,
Remasterrecordlabel, Remastercataloguenumber)
) AS RemIdent
- FROM torrents AS t
- WHERE t.GroupID IN(".implode(',', $SnatchedGroupIDs).")
- AND t.Format IN ('FLAC', 'MP3')
- GROUP BY t.GroupID, RemIdent");
+ FROM torrents
+ WHERE GroupID IN (".implode(',', $SnatchedGroupIDs).")
+ AND Format IN ('FLAC', 'MP3')
+ GROUP BY GroupID, RemIdent");
$DB->query("
SELECT GroupID
diff --git a/sections/better/tags.php b/sections/better/tags.php
index 6de556de..07622c49 100644
--- a/sections/better/tags.php
+++ b/sections/better/tags.php
@@ -17,7 +17,7 @@
$Join = '';
$All = true;
} else {
- $Join = "JOIN xbt_snatched as x ON x.fid = tbt.TorrentID AND x.uid = ".$LoggedUser['ID'];
+ $Join = "JOIN xbt_snatched AS x ON x.fid = tbt.TorrentID AND x.uid = ".$LoggedUser['ID'];
$All = false;
}
diff --git a/sections/better/upload.php b/sections/better/upload.php
index b6be6d48..1de3c51e 100644
--- a/sections/better/upload.php
+++ b/sections/better/upload.php
@@ -34,16 +34,16 @@
$DB->query("
CREATE TEMPORARY TABLE temp_sections_better_upload
SELECT
- t.GroupID,
- GROUP_CONCAT(t.Encoding SEPARATOR ' ') AS EncodingList,
+ GroupID,
+ GROUP_CONCAT(Encoding SEPARATOR ' ') AS EncodingList,
CRC32(CONCAT_WS(
' ', Media, Remasteryear, Remastertitle,
Remasterrecordlabel, Remastercataloguenumber)
) AS RemIdent
- FROM torrents AS t
- WHERE t.GroupID IN(".implode(',', $UploadedGroupIDs).")
- AND t.Format IN ('FLAC', 'MP3')
- GROUP BY t.GroupID, RemIdent");
+ FROM torrents
+ WHERE GroupID IN (".implode(',', $UploadedGroupIDs).")
+ AND Format IN ('FLAC', 'MP3')
+ GROUP BY GroupID, RemIdent");
$DB->query("
SELECT GroupID
diff --git a/sections/forums/ajax_get_edit.php b/sections/forums/ajax_get_edit.php
index 4889ff03..c0910ac4 100644
--- a/sections/forums/ajax_get_edit.php
+++ b/sections/forums/ajax_get_edit.php
@@ -26,10 +26,10 @@
$Edits = $Cache->get_value($Type.'_edits_'.$PostID);
if (!is_array($Edits)) {
$DB->query("
- SELECT ce.EditUser, ce.EditTime, ce.Body
- FROM comments_edits AS ce
+ SELECT EditUser, EditTime, Body
+ FROM comments_edits
WHERE Page = '$Type' AND PostID = $PostID
- ORDER BY ce.EditTime DESC");
+ ORDER BY EditTime DESC");
$Edits = $DB->to_array();
$Cache->cache_value($Type.'_edits_'.$PostID, $Edits, 0);
}
diff --git a/sections/forums/forum.php b/sections/forums/forum.php
index 8e22e83b..bd0f281e 100644
--- a/sections/forums/forum.php
+++ b/sections/forums/forum.php
@@ -37,18 +37,18 @@
if (!isset($Forum) || !is_array($Forum)) {
$DB->query("
SELECT
- t.ID,
- t.Title,
- t.AuthorID,
- t.IsLocked,
- t.IsSticky,
- t.NumPosts,
- t.LastPostID,
- t.LastPostTime,
- t.LastPostAuthorID
- FROM forums_topics AS t
- WHERE t.ForumID = '$ForumID'
- ORDER BY t.Ranking = 0, t.Ranking ASC, t.IsSticky DESC, t.LastPostTime DESC
+ ID,
+ Title,
+ AuthorID,
+ IsLocked,
+ IsSticky,
+ NumPosts,
+ LastPostID,
+ LastPostTime,
+ LastPostAuthorID
+ FROM forums_topics
+ WHERE ForumID = '$ForumID'
+ ORDER BY Ranking = 0, Ranking ASC, IsSticky DESC, LastPostTime DESC
LIMIT $Limit"); // Can be cached until someone makes a new post
$Forum = $DB->to_array('ID', MYSQLI_ASSOC, false);
@@ -175,15 +175,15 @@
l.TopicID,
l.PostID,
CEIL((
- SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = l.TopicID
- AND forums_posts.ID <= l.PostID
+ SELECT COUNT(p.ID)
+ FROM forums_posts AS p
+ WHERE p.TopicID = l.TopicID
+ AND p.ID <= l.PostID
) / $PerPage
) AS Page
FROM forums_last_read_topics AS l
- WHERE TopicID IN(".implode(', ', array_keys($Forum)).')
- AND UserID = \''.$LoggedUser['ID'].'\'');
+ WHERE l.TopicID IN (".implode(', ', array_keys($Forum)).')
+ AND l.UserID = \''.$LoggedUser['ID'].'\'');
// Turns the result set into a multi-dimensional array, with
// forums_last_read_topics.TopicID as the key.
diff --git a/sections/forums/get_post.php b/sections/forums/get_post.php
index 33efea05..18025edc 100644
--- a/sections/forums/get_post.php
+++ b/sections/forums/get_post.php
@@ -24,8 +24,8 @@
SELECT
p.Body,
t.ForumID
- FROM forums_posts as p
- JOIN forums_topics as t on p.TopicID = t.ID
+ FROM forums_posts AS p
+ JOIN forums_topics AS t ON p.TopicID = t.ID
WHERE p.ID='$PostID'");
list($Body, $ForumID) = $DB->next_record(MYSQLI_NUM);
diff --git a/sections/forums/take_warn.php b/sections/forums/take_warn.php
index 4acf9b4f..9e3be20f 100644
--- a/sections/forums/take_warn.php
+++ b/sections/forums/take_warn.php
@@ -53,15 +53,15 @@
t.ForumID,
CEIL(
(
- SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = p.TopicID
- AND forums_posts.ID <= '$PostID'
+ SELECT COUNT(p2.ID)
+ FROM forums_posts AS p2
+ WHERE p2.TopicID = p.TopicID
+ AND p2.ID <= '$PostID'
) / " . POSTS_PER_PAGE . "
) AS Page
- FROM forums_posts as p
- JOIN forums_topics as t on p.TopicID = t.ID
- JOIN forums as f ON t.ForumID = f.ID
+ FROM forums_posts AS p
+ JOIN forums_topics AS t ON p.TopicID = t.ID
+ JOIN forums AS f ON t.ForumID = f.ID
WHERE p.ID = '$PostID'");
list($OldBody, $AuthorID, $TopicID, $ForumID, $Page) = $DB->next_record();
diff --git a/sections/forums/takeedit.php b/sections/forums/takeedit.php
index aa13b8bc..88622750 100644
--- a/sections/forums/takeedit.php
+++ b/sections/forums/takeedit.php
@@ -42,15 +42,15 @@
t.ForumID,
f.MinClassWrite,
CEIL((
- SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = p.TopicID
- AND forums_posts.ID <= '$PostID'
+ SELECT COUNT(p2.ID)
+ FROM forums_posts AS p2
+ WHERE p2.TopicID = p.TopicID
+ AND p2.ID <= '$PostID'
) / ".POSTS_PER_PAGE."
) AS Page
- FROM forums_posts as p
- JOIN forums_topics as t on p.TopicID = t.ID
- JOIN forums as f ON t.ForumID = f.ID
+ FROM forums_posts AS p
+ JOIN forums_topics AS t ON p.TopicID = t.ID
+ JOIN forums AS f ON t.ForumID = f.ID
WHERE p.ID = '$PostID'");
list($OldBody, $AuthorID, $TopicID, $IsLocked, $ForumID, $MinClassWrite, $Page) = $DB->next_record();
diff --git a/sections/forums/thread.php b/sections/forums/thread.php
index d48a534c..daa9c4bb 100644
--- a/sections/forums/thread.php
+++ b/sections/forums/thread.php
@@ -102,7 +102,7 @@
p.EditedUserID,
p.EditedTime,
ed.Username
- FROM forums_posts as p
+ FROM forums_posts AS p
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
WHERE p.TopicID = '$ThreadID'
AND p.ID != '".$ThreadInfo['StickyPostID']."'
diff --git a/sections/forums/warn.php b/sections/forums/warn.php
index 738f251d..bc99e8d1 100644
--- a/sections/forums/warn.php
+++ b/sections/forums/warn.php
@@ -10,8 +10,8 @@
$UserInfo = Users::user_info($UserID);
$DB->query("
SELECT p.Body, t.ForumID
- FROM forums_posts as p
- JOIN forums_topics as t on p.TopicID = t.ID
+ FROM forums_posts AS p
+ JOIN forums_topics AS t ON p.TopicID = t.ID
WHERE p.ID = '$PostID'");
list($PostBody, $ForumID) = $DB -> next_record();
View::show_header('Warn User');
diff --git a/sections/inbox/conversation.php b/sections/inbox/conversation.php
index cc17204d..23e9de9c 100644
--- a/sections/inbox/conversation.php
+++ b/sections/inbox/conversation.php
@@ -74,7 +74,7 @@
// Get messages
$DB->query("
SELECT SentDate, SenderID, Body, ID
- FROM pm_messages AS m
+ FROM pm_messages
WHERE ConvID = '$ConvID'
ORDER BY ID");
?>
diff --git a/sections/inbox/get_post.php b/sections/inbox/get_post.php
index b9295da3..452c082f 100644
--- a/sections/inbox/get_post.php
+++ b/sections/inbox/get_post.php
@@ -23,7 +23,7 @@
$DB->query("
SELECT
m.Body
- FROM pm_messages as m
+ FROM pm_messages AS m
JOIN pm_conversations_users AS u ON m.ConvID=u.ConvID
WHERE m.ID='$PostID'
AND u.UserID=".$LoggedUser['ID']);
diff --git a/sections/peerupdate/index.php b/sections/peerupdate/index.php
index dbfbb2b4..258f3723 100644
--- a/sections/peerupdate/index.php
+++ b/sections/peerupdate/index.php
@@ -32,8 +32,8 @@
$DB->query("
INSERT INTO tpc_temp
SELECT t2.*
- FROM torrents_peerlists t1
- JOIN torrents_peerlists_compare t2
+ FROM torrents_peerlists AS t1
+ JOIN torrents_peerlists_compare AS t2
USING(TorrentID)
WHERE t1.Seeders != t2.Seeders
OR t1.Leechers != t2.Leechers
diff --git a/sections/questions/questions.php b/sections/questions/questions.php
index e253011d..bc55ba48 100644
--- a/sections/questions/questions.php
+++ b/sections/questions/questions.php
@@ -13,8 +13,8 @@
uq.Date,
(
SELECT COUNT(1)
- FROM staff_answers
- WHERE QuestionID = uq.ID
+ FROM staff_answers AS sa
+ WHERE sa.QuestionID = uq.ID
) AS Responses
FROM user_questions AS uq
WHERE uq.ID NOT IN
diff --git a/sections/reports/compose.php b/sections/reports/compose.php
index 8129c34f..3042dff2 100644
--- a/sections/reports/compose.php
+++ b/sections/reports/compose.php
@@ -103,13 +103,13 @@
p.ID,
p.Body,
p.TopicID,
- ( SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = p.TopicID
- AND forums_posts.ID<=p.ID
+ ( SELECT COUNT(p2.ID)
+ FROM forums_posts AS p2
+ WHERE p2.TopicID = p.TopicID
+ AND p2.ID <= p.ID
) AS PostNum
FROM forums_posts AS p
- WHERE ID=$ThingID");
+ WHERE p.ID = $ThingID");
if (!$DB->has_results()) {
$Error = 'No forum post with the reported ID found';
} else {
@@ -121,7 +121,7 @@
case 'comment':
$DB->query("
SELECT 1
- FROM comments AS c
+ FROM comments
WHERE ID = $ThingID");
if (!$DB->has_results()) {
$Error = 'No comment with the reported ID found';
@@ -139,9 +139,9 @@
}
$DB->query("
- SELECT r.Reason
- FROM reports AS r
- WHERE r.ID = $ReportID");
+ SELECT Reason
+ FROM reports
+ WHERE ID = $ReportID");
list($Reason) = $DB->next_record();
$Body = "You reported $TypeLink for the reason:\n[quote]{$Reason}[/quote]";
diff --git a/sections/reports/reports.php b/sections/reports/reports.php
index c22597bc..3bbf30b0 100644
--- a/sections/reports/reports.php
+++ b/sections/reports/reports.php
@@ -168,24 +168,25 @@
p.ID,
p.Body,
p.TopicID,
- ( SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = p.TopicID
- AND forums_posts.ID <= p.ID
+ (
+ SELECT COUNT(p2.ID)
+ FROM forums_posts AS p2
+ WHERE p2.TopicID = p.TopicID
+ AND p2.ID <= p.ID
) AS PostNum
FROM forums_posts AS p
- WHERE ID = $ThingID");
+ WHERE p.ID = $ThingID");
if (!$DB->has_results()) {
echo 'No forum post with the reported ID found';
} else {
list($PostID, $Body, $TopicID, $PostNum) = $DB->next_record();
- echo "FORUM POST";
+ echo "FORUM POST ID #$PostID";
}
break;
case 'comment':
$DB->query("
SELECT 1
- FROM comments AS c
+ FROM comments
WHERE ID = $ThingID");
if (!$DB->has_results()) {
echo 'No comment with the reported ID found';
diff --git a/sections/reports/stats.php b/sections/reports/stats.php
index 3b8b8149..69e1c714 100644
--- a/sections/reports/stats.php
+++ b/sections/reports/stats.php
@@ -154,11 +154,11 @@
$DB->query("
SELECT u.Username,
- COUNT(LastPostAuthorID) as Trashed
- FROM forums_topics as f
- LEFT JOIN users_main as u on u.id = LastPostAuthorID
- WHERE ForumID = 12
- GROUP BY LastPostAuthorID
+ COUNT(f.LastPostAuthorID) as Trashed
+ FROM forums_topics AS f
+ LEFT JOIN users_main AS u ON u.ID = f.LastPostAuthorID
+ WHERE f.ForumID = 12
+ GROUP BY f.LastPostAuthorID
ORDER BY Trashed DESC
LIMIT 30");
$Results = $DB->to_array();
diff --git a/sections/reports/takereport.php b/sections/reports/takereport.php
index d26e8ebd..01f37892 100644
--- a/sections/reports/takereport.php
+++ b/sections/reports/takereport.php
@@ -46,13 +46,13 @@
SELECT
p.ID,
p.TopicID,
- ( SELECT COUNT(ID)
- FROM forums_posts
- WHERE forums_posts.TopicID = p.TopicID
- AND forums_posts.ID <= p.ID
+ ( SELECT COUNT(p2.ID)
+ FROM forums_posts AS p2
+ WHERE p2.TopicID = p.TopicID
+ AND p2.ID <= p.ID
) AS PostNum
FROM forums_posts AS p
- WHERE ID = $ID");
+ WHERE p.ID = $ID");
list($PostID, $TopicID, $PostNum) = $DB->next_record();
$Link = "forums.php?action=viewthread&threadid=$TopicID&post=$PostNum#post$PostID";
break;
diff --git a/sections/reportsv2/views.php b/sections/reportsv2/views.php
index 9889cab5..66ee2661 100644
--- a/sections/reportsv2/views.php
+++ b/sections/reportsv2/views.php
@@ -270,11 +270,11 @@
$DB->query("
SELECT
- r.Type,
- COUNT(r.ID) AS Count
- FROM reportsv2 AS r
- WHERE r.Status = 'New'
- GROUP BY r.Type");
+ Type,
+ COUNT(ID) AS Count
+ FROM reportsv2
+ WHERE Status = 'New'
+ GROUP BY Type");
$Current = $DB->to_array();
if (!empty($Current)) {
?>
diff --git a/sections/requests/take_new_edit.php b/sections/requests/take_new_edit.php
index aedd72c3..665e4c6e 100644
--- a/sections/requests/take_new_edit.php
+++ b/sections/requests/take_new_edit.php
@@ -391,12 +391,12 @@
//1. See if each artist given already exists and if it does, grab the ID.
$DB->query("
SELECT
- aa.ArtistID,
- aa.AliasID,
- aa.Name,
- aa.Redirect
- FROM artists_alias AS aa
- WHERE aa.Name = '".db_string($Artist['name'])."'");
+ ArtistID,
+ AliasID,
+ Name,
+ Redirect
+ FROM artists_alias
+ WHERE Name = '".db_string($Artist['name'])."'");
while (list($ArtistID, $AliasID, $AliasName, $Redirect) = $DB->next_record(MYSQLI_NUM, false)) {
if (!strcasecmp($Artist['name'], $AliasName)) {
@@ -457,14 +457,14 @@
//Get a count of how many groups or requests use the artist ID
$DB->query("
SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
+ FROM artists_group AS ag
LEFT JOIN requests_artists AS ra ON ag.ArtistID = ra.ArtistID
WHERE ra.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
list($ReqCount) = $DB->next_record();
$DB->query("
SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
+ FROM artists_group AS ag
LEFT JOIN torrents_artists AS ta ON ag.ArtistID = ta.ArtistID
WHERE ta.ArtistID IS NOT NULL
AND ag.ArtistID = '$ArtistID'");
diff --git a/sections/schedule/index.php b/sections/schedule/index.php
index 3bf8c020..8399c568 100644
--- a/sections/schedule/index.php
+++ b/sections/schedule/index.php
@@ -572,7 +572,7 @@ function next_hour() {
INSERT INTO users_torrent_history_snatch (UserID, NumSnatches)
SELECT xs.uid, COUNT(DISTINCT xs.fid)
FROM xbt_snatched AS xs
- JOIN torrents on torrents.ID = xs.fid
+ JOIN torrents AS t ON t.ID = xs.fid
GROUP BY xs.uid");
// Get the fraction of snatched torrents seeded for at least 72 hours this week
@@ -864,8 +864,8 @@ function next_hour() {
//------------- Demote users --------------------------------------------//
sleep(10);
$DB->query('
- SELECT um.ID
- FROM users_main AS um
+ SELECT ID
+ FROM users_main
WHERE PermissionID IN('.POWER.', '.ELITE.', '.TORRENT_MASTER.')
AND Uploaded / Downloaded < 0.95
OR PermissionID IN('.POWER.', '.ELITE.', '.TORRENT_MASTER.')
@@ -889,8 +889,8 @@ function next_hour() {
echo "demoted 2\n";
$DB->query('
- SELECT um.ID
- FROM users_main AS um
+ SELECT ID
+ FROM users_main
WHERE PermissionID IN('.MEMBER.', '.POWER.', '.ELITE.', '.TORRENT_MASTER.')
AND Uploaded / Downloaded < 0.65');
echo "demoted 3\n";
@@ -1363,7 +1363,7 @@ function next_hour() {
$DB->query("
SELECT ID
FROM users_main AS um
- JOIN users_info AS ui on ui.UserID = um.ID
+ JOIN users_info AS ui ON ui.UserID = um.ID
WHERE um.Enabled = '1'
AND ui.DisableInvites = '0'
AND ((um.PermissionID = ".POWER."
diff --git a/sections/staffpm/ajax_delete_response.php b/sections/staffpm/ajax_delete_response.php
index d96a0ac8..de824663 100644
--- a/sections/staffpm/ajax_delete_response.php
+++ b/sections/staffpm/ajax_delete_response.php
@@ -6,9 +6,9 @@
SELECT
i.SupportFor,
p.DisplayStaff
- FROM users_info as i
- JOIN users_main as m ON m.ID = i.UserID
- JOIN permissions as p ON p.ID = m.PermissionID
+ FROM users_info AS i
+ JOIN users_main AS m ON m.ID = i.UserID
+ JOIN permissions AS p ON p.ID = m.PermissionID
WHERE i.UserID = ".$LoggedUser['ID']
);
list($SupportFor, $DisplayStaff) = $DB->next_record();
diff --git a/sections/staffpm/ajax_edit_response.php b/sections/staffpm/ajax_edit_response.php
index 1df04f72..8e19c282 100644
--- a/sections/staffpm/ajax_edit_response.php
+++ b/sections/staffpm/ajax_edit_response.php
@@ -5,9 +5,9 @@
SELECT
i.SupportFor,
p.DisplayStaff
- FROM users_info as i
- JOIN users_main as m ON m.ID = i.UserID
- JOIN permissions as p ON p.ID = m.PermissionID
+ FROM users_info AS i
+ JOIN users_main AS m ON m.ID = i.UserID
+ JOIN permissions AS p ON p.ID = m.PermissionID
WHERE i.UserID = '.$LoggedUser['ID']
);
list($SupportFor, $DisplayStaff) = $DB->next_record();
diff --git a/sections/staffpm/ajax_get_response.php b/sections/staffpm/ajax_get_response.php
index bed77682..e2a6ad7f 100644
--- a/sections/staffpm/ajax_get_response.php
+++ b/sections/staffpm/ajax_get_response.php
@@ -6,9 +6,9 @@
SELECT
i.SupportFor,
p.DisplayStaff
- FROM users_info as i
- JOIN users_main as m ON m.ID = i.UserID
- JOIN permissions as p ON p.ID = m.PermissionID
+ FROM users_info AS i
+ JOIN users_main AS m ON m.ID = i.UserID
+ JOIN permissions AS p ON p.ID = m.PermissionID
WHERE i.UserID = ".$LoggedUser['ID']
);
list($SupportFor, $DisplayStaff) = $DB->next_record();
diff --git a/sections/staffpm/get_post.php b/sections/staffpm/get_post.php
index 175781ee..44060aa5 100644
--- a/sections/staffpm/get_post.php
+++ b/sections/staffpm/get_post.php
@@ -23,7 +23,7 @@
// the right level
$DB->query("
SELECT m.Message, c.Level, c.UserID
- FROM staff_pm_messages as m
+ FROM staff_pm_messages AS m
JOIN staff_pm_conversations AS c ON m.ConvID = c.ID
WHERE m.ID = '$PostID'");
list($Message, $Level, $UserID) = $DB->next_record(MYSQLI_NUM);
diff --git a/sections/staffpm/index.php b/sections/staffpm/index.php
index e8d39233..76ce66f5 100644
--- a/sections/staffpm/index.php
+++ b/sections/staffpm/index.php
@@ -10,9 +10,9 @@
SELECT
i.SupportFor,
p.DisplayStaff
- FROM users_info as i
- JOIN users_main as m ON m.ID = i.UserID
- JOIN permissions as p ON p.ID = m.PermissionID
+ FROM users_info AS i
+ JOIN users_main AS m ON m.ID = i.UserID
+ JOIN permissions AS p ON p.ID = m.PermissionID
WHERE i.UserID = ".$LoggedUser['ID']
);
list($SupportFor, $DisplayStaff) = $DB->next_record();
diff --git a/sections/staffpm/viewconv.php b/sections/staffpm/viewconv.php
index cfb4c206..1dcbcbb1 100644
--- a/sections/staffpm/viewconv.php
+++ b/sections/staffpm/viewconv.php
@@ -187,8 +187,8 @@
SELECT
m.ID,
m.Username
- FROM permissions as p
- JOIN users_main as m ON m.PermissionID = p.ID
+ FROM permissions AS p
+ JOIN users_main AS m ON m.PermissionID = p.ID
WHERE p.DisplayStaff = '1'
ORDER BY p.Level DESC, m.Username ASC"
);
@@ -206,9 +206,9 @@
SELECT
m.ID,
m.Username
- FROM users_info as i
- JOIN users_main as m ON m.ID = i.UserID
- JOIN permissions as p ON p.ID = m.PermissionID
+ FROM users_info AS i
+ JOIN users_main AS m ON m.ID = i.UserID
+ JOIN permissions AS p ON p.ID = m.PermissionID
WHERE p.DisplayStaff != '1'
AND i.SupportFor != ''
ORDER BY m.Username ASC
diff --git a/sections/tools/data/invite_pool.php b/sections/tools/data/invite_pool.php
index dca1e031..9413fe3d 100644
--- a/sections/tools/data/invite_pool.php
+++ b/sections/tools/data/invite_pool.php
@@ -28,7 +28,7 @@
i.InviteKey,
i.Expires,
i.Email
- FROM invites as i
+ FROM invites AS i
JOIN users_main AS um ON um.ID = i.InviterID ";
if ($Search) {
$sql .= "
diff --git a/sections/tools/data/special_users.php b/sections/tools/data/special_users.php
index 99804340..eb2927ae 100644
--- a/sections/tools/data/special_users.php
+++ b/sections/tools/data/special_users.php
@@ -7,10 +7,10 @@
$DB->query("
- SELECT m.ID
- FROM users_main AS m
- WHERE m.CustomPermissions != ''
- AND m.CustomPermissions != 'a:0:{}'");
+ SELECT ID
+ FROM users_main
+ WHERE CustomPermissions != ''
+ AND CustomPermissions != 'a:0:{}'");
if ($DB->has_results()) {
?>
diff --git a/sections/tools/managers/bans.php b/sections/tools/managers/bans.php
index bd8be1cd..24b1aca8 100644
--- a/sections/tools/managers/bans.php
+++ b/sections/tools/managers/bans.php
@@ -58,7 +58,7 @@
FromIP,
ToIP,
Reason
- FROM ip_bans AS i ";
+ FROM ip_bans ";
if (!empty($_REQUEST['notes'])) {
$sql .= "WHERE Reason LIKE '%".db_string($_REQUEST['notes'])."%' ";
diff --git a/sections/tools/managers/dnu_list.php b/sections/tools/managers/dnu_list.php
index 6464e4fa..1386391b 100644
--- a/sections/tools/managers/dnu_list.php
+++ b/sections/tools/managers/dnu_list.php
@@ -12,8 +12,8 @@
d.Comment,
d.UserID,
d.Time
- FROM do_not_upload as d
- LEFT JOIN users_main AS um ON um.ID=d.UserID
+ FROM do_not_upload AS d
+ LEFT JOIN users_main AS um ON um.ID=d.UserID
ORDER BY d.Sequence");
?>