From 1d1e7d369080702f82a4cf1cc528928a54e6a6b2 Mon Sep 17 00:00:00 2001 From: Snap Date: Tue, 5 May 2015 16:47:00 -0700 Subject: Partial multiple channels for chat implementation --- includes/chats.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'includes/chats.php') diff --git a/includes/chats.php b/includes/chats.php index d9616fd..92bd90e 100644 --- a/includes/chats.php +++ b/includes/chats.php @@ -34,27 +34,27 @@ function muteUser($userID, $numMinutes) { -function addChat($userID, $message) { +function addChat($userID, $message, $channel = 1) { global $mysqli; if ($message == '') return; $stmt = $mysqli->prepare("INSERT INTO `chat` - (`userID`, `message`) - VALUES (?, ?)"); - $stmt->bind_param('is', $userID, $message); + (`userID`, `message`, `channel`) + VALUES (?, ?, ?)"); + $stmt->bind_param('isi', $userID, $message, $channel); $stmt->execute(); $ID = $stmt->insert_id; $stmt->close(); //Turnicate messages. - $deleteFromID = $ID - CHAT_ROWS_TO_KEEP; - $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); + //$deleteFromID = $ID - CHAT_ROWS_TO_KEEP; + //$mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID"); return $ID; } -function getChat($startID = 0) { +function getChat($startID = 0, $channel = 1) { global $mysqli; if (!is_numeric($startID)) return false; @@ -74,19 +74,22 @@ function getChat($startID = 0) { LEFT JOIN `users` ON chat.userID = users.ID WHERE chat.ID > '$startID' - ORDER BY chat.dateSent ASC, chat.ID ASC - ")) { - $array = array(); + AND chat.channel = '$channel' + ORDER BY chat.dateSent DESC, chat.ID DESC + LIMIT " . CHAT_ROWS_TO_KEEP) + ) { + $chatData = array(); if ($res->num_rows == 0) { $res->close(); return false; } while ($response = $res->fetch_assoc()) { - $array[] = $response; + $chatData[] = $response; } $res->close(); - if (count($array) < 1) return false; - return $array; + if (count($chatData) < 1) return false; + $chatData = array_reverse($chatData); + return $chatData; } else { printf("DError: %s\n", $mysqli->error); return false; -- cgit v1.2.3