diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-01-15 01:22:15 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-01-15 01:22:15 -0800 |
commit | 43067b7e18c0bd44f703a8bee8770bcdab674f20 (patch) | |
tree | 4f492083a9675bb6cefec53d6e1c1f0da1870643 /includes | |
parent | cb9620d7917cc7fa4aeee54b21d32593a50b081c (diff) | |
download | pathery-43067b7e18c0bd44f703a8bee8770bcdab674f20.tar.xz |
This is the chat app* whoops.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/chats.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/includes/chats.php b/includes/chats.php new file mode 100644 index 0000000..56c88d1 --- /dev/null +++ b/includes/chats.php @@ -0,0 +1,74 @@ +<?
+/*
+ * addChat, getChat functions
+*/
+include_once('sqli.php');
+
+define('CHAT_ROWS_TO_KEEP', 30);
+
+
+function addChat($userID, $message) {
+ global $mysqli;
+
+ $stmt = $mysqli->prepare("INSERT INTO `chat`
+ (`userID`, `message`)
+ VALUES (?, ?)");
+ $stmt->bind_param('is', $userID, $message);
+ $stmt->execute();
+
+ $ID = $stmt->insert_id;
+ $stmt->close();
+ // $mysqli->close;
+ return $ID;
+}
+
+function getChat($startID = 0) {
+ global $mysqli;
+ $array = array();
+
+ if (!is_numeric($startID))
+ return false;
+
+ //Not sure why this happens; but just return nothing..
+ if (!is_object($mysqli))
+ die("Error creating object");
+
+ $res = $mysqli->query("
+ SELECT
+ chat.ID, chat.userID, chat.message, chat.dateSent,
+ users.displayName,
+ userData.displayColor,
+ userData.wallColor,
+ userData.wallEmblem
+ FROM `chat`
+ LEFT JOIN `userData`
+ ON chat.userID = userData.userID
+ LEFT JOIN `users`
+ ON chat.userID = users.ID
+ WHERE chat.ID > '$startID'
+ ORDER BY chat.ID ASC
+ ");
+ $array = array();
+ if ($res->num_rows == 0) {
+ $res->close();
+ return false;
+ }
+ while ($response = $res->fetch_assoc()) {
+ $array[] = $response;
+ $lastID = $response['ID'];
+ }
+ $res->close();
+
+ if (count($array) < 1)
+ return false;
+
+ //Turnicate messages.
+ $deleteFromID = $lastID - CHAT_ROWS_TO_KEEP;
+ $mysqli->query("DELETE FROM `chat` WHERE `ID` < $deleteFromID");
+ $mysqli->close();
+
+ return $array;
+}
+
+
+?>
\ No newline at end of file |