-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetlastmsg.php
More file actions
55 lines (40 loc) · 1.28 KB
/
getlastmsg.php
File metadata and controls
55 lines (40 loc) · 1.28 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
header("Content-type: text/xml");
echo chr(60) . chr(63) . 'xml version="1.0" encoding="utf-8" ' . chr(63) . chr(62);
?>
<?php
session_start();
$hostname = "localhost";
$username = "db";
$password = "db";
$dbName = "forum";
$msgtable = "messages";
$usrtable = "users";
$topic = isset($_GET['topic']) ? $_GET['topic'] : 1;
$id = $_SESSION['user_id'];
mysql_connect($hostname, $username, $password) OR DIE("unable to connect to database ");
mysql_select_db($dbName) or die(mysql_error());
$query = "SELECT *
FROM $msgtable
WHERE topic_id =$topic
AND creator =$id
ORDER BY creationdate DESC
LIMIT 0 , 1";
$posts = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($posts)) {
echo '<post>';
$creator = $id;
$usr = mysql_query("SELECT * FROM $usrtable WHERE id=$id");
$usra = mysql_fetch_array($usr)['avatar'];
$usr = mysql_fetch_array($usr)['nick'];
$dt = $row['creationdate'];
$num = $row['message_id'];
echo '<text>' . htmlspecialchars($row['text']) . '</text>';
echo '<creator>' . htmlspecialchars($usr) . '</creator>';
echo '<date>' . htmlspecialchars($dt) . '</date>';
echo '<num>' . htmlspecialchars($num) . '</num>';
echo '<avatar>' . htmlspecialchars($usra) . '</avatar>';
echo '</post>';
}
mysql_close();
?>