Log in

View Full Version : Barebones code to use Javascript to display active topics.


shri
06-05-2001, 04:08 PM
Ok.. 5 minute hack based on a request by Craig.

put this in a file called activejs.php in your forum directory.


<?
include('./global.php');

$num_topics = 5;

$topics_result = $DB_site->query("select * from thread order by lastpost desc limit $num_topics");


while($topics = $DB_site->fetch_array($topics_result)) {
$mytitle = addslashes($topics[title]);
echo ("document.write('<a href=$bburl/showthread.php?threadid=$topics[threadid]>$mytitle</a><br>');\n");
}

?>


On the page where you want to display the topics put the following.


<html>
<head>
</head>
<body>
<script LANGUAGE="JavaScript" src="http://www.hkindians.com/forum/activejs.php">
</script>
</body>
</html>

Craig Antill
06-05-2001, 07:44 PM
Nice one!! It'll be put to good use - thanks! :D

Steve Machol
06-05-2001, 08:35 PM
Nice and easy! The only reason I wouldn't use this is because it includes messages in my private forums. Can this be modifed to ignore privtae forums?

shri
06-06-2001, 12:09 AM
Play with the select statement.

Steve Machol
06-06-2001, 04:00 AM
[QUOTE]Originally posted by shri
Play with the select statement.

shri
06-06-2001, 04:45 AM
SELECT * FROM thread WHERE thread.visible=1 and (forumid<>'20' and forumid <> '24' and forumid <> 25 and forumid <> '27' and forumid <> '13' and forumid<> '28') ORDER BY lastpost desc LIMIT 10


You can adapt it. This is simpler but not automated. The automated procedure would be to look at the permissions and see what forums were not viewable by guests and then display the "open forums".

Additionally if you have lots of threads (I have over 30K on one of my forums) you can limit the number of rows scanned by doing something like this in your php code. (You need to add an index on the field 'lastpost' for the table thread).

[php]
$twentyfourhours= 24*60*60;
$date1 = time() - $twentyfourhours * 1;
[php]

Make your select statement ...


SELECT * FROM thread WHERE thread.visible=1 and (forumid<>'20' and forumid <> '24' and forumid <> 25 and forumid <> '27' and forumid <> '13' and forumid<> '28') and (lastpost > date1) ORDER BY lastpost desc LIMIT 10

Craig Antill
06-08-2001, 04:35 PM
Any idea how to add the date of the post ? One of my partner sites is asking for this to harmonise with the rest of their data on their site :)