-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpChatAjax.php
executable file
·37 lines (30 loc) · 1.13 KB
/
pChatAjax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
session_start();
include "pConnect.php";
global $conn;
if(isset($_GET["s"])){
if($_GET["s"] == "")
return;
$conn->query("INSERT INTO chatMessages (userid, message, dateTime) VALUES ('".$_SESSION["id"]."', '".$_GET["s"]."', '".date("Y-m-d H:i:s")."')");
}else if(isset($_GET["r"])){
$retVal = "";
if(!is_numeric($_GET["r"]))
$numRows = 20;
else
$numRows = $_GET["r"];
if($numRows > 100)
$numRows = 100;
$retVal = "";
$search = $conn->query("SELECT * FROM chatMessages ORDER BY dateTime DESC LIMIT ".$numRows);
while($row = $search->fetch_assoc()){
$userRow = $conn->query("SELECT * FROM users WHERE id=".$row[userid]." LIMIT 1")->fetch_assoc();
$retUserRow = "<tr><td><i>".$row["dateTime"]."</i> <b>-</b> ";
if($userRow["id"] == $_SESSION["id"])
$retUserRow = $retUserRow."<font color='red'>";
else
$retUserRow = $retUserRow."<font color='blue'>";
$retUserRow = $retUserRow.$userRow["username"]."</font> <b>---> </b>".$row["message"]."</td></tr></br>";
$retVal = $retUserRow.$retVal;
}
echo $retVal;
}