Re: Same user ID in WP
Posted: Mon Jan 13, 2020 4:55 pm
On Last topic can display by last "topic_id" and for last post by "post_id" or i need to make sql script ...
Or something wrong ?
Code: Select all
<body bgcolor="black" link="blue" alink="blue" vlink="blue"><font size="1" color="blue"><center>Last 10 topics</center>
<?
function mysqlerror($err) {
global $mysql;
if ($mysql == "off") return;
echo $err . "<br><b>" . mysql_error() . "</b>";
exit;
}
function mysqlconnect() {
global $mysqlid, $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb;
if ($mysqlid) return;
$mysqlid = mysql_connect($mysqlhost, $mysqllogin, $mysqlpass) or mysqlerror("Can not connect to $mysqlhost");
mysql_select_db($mysqldb, $mysqlid) or mysqlerror("Missing DB $mysqldb");
}
function mysqlclose() {
global $mysqlid;
if ($mysqlid) @mysql_close($mysqlid);
}
function mysqlquery($sql) {
global $mysqlid;
if (!$mysqlid) mysqlconnect();
$res = mysql_query($sql, $mysqlid) or mysqlerror($sql);
return $res;
}
register_shutdown_function("mysqlclose");
// MySQL loading ----------------------------------------------
$mysqlid = 0;
$mysqlhost = 'Host';
$mysqldb = 'DB';
$mysqllogin = 'User';
$mysqlpass = 'Pass';
mysqlconnect();
// END MySQL loading ----------------------------------------------
$table_prefix = "Tabble prefix phpbb_";
$forum_url = "http://Forum URL";
$news_forum_id = 2;
$number_of_news = 10;
$date_format = "d.m.Y, G:i:s";
$query = "SELECT
t.`topic_id`,
t.`topic_title`,
p.`post_time`,
p.`post_username`,
p.`poster_id`,
u.`username`
FROM
`" . $table_prefix . "topics` as t,
`" . $table_prefix . "posts` as p,
`" . $table_prefix . "posts_text` as pt,
`" . $table_prefix . "users` as u
WHERE
t.`topic_first_post_id` = p.`post_id` AND
t.`topic_first_post_id` = pt.`post_id` AND
p.`poster_id` = u.`user_id` AND
t.`forum_id` = '" . $news_forum_id . "'
ORDER BY p.`post_time` DESC
LIMIT $number_of_news";
$result = mysqlquery($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<br>
<a href="<?= $forum_url ?>viewtopic.php?t=<?= $row['topic_id'] ?>">
<?= $row['topic_title'] ?>
<?= nl2br($row['post_text']) ?>
<? } ?>
</font></body>