TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

July 20, 2024, 05:45:49 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,333
  • Total Topics: 21,233
  • Online today: 133
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 71
  • Total: 72
  • @rjen

Random Topic Link

Started by evilicy, August 04, 2008, 01:15:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

evilicy

Click on the link and it takes you to a random topic on your forum.

In php block:

$query  = "SELECT ID_TOPIC FROM smf_messages ORDER BY RAND() LIMIT 1";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href='http://www.darkvoid.org/index.php?topic={$row['ID_TOPIC']}.0 '>Click for a Random Topic</a>";
}


Not sure if this was the best way to do this but it works  :P

Ianedres

This would assume that the topic selected through the query is available to everyone... correct?

Doesn't appear to check whether the topic appears in a board available/not available to the current visitor.

evilicy

Well if the random topic is on a board they can't access they will simply get

"An Error Has Occurred!
The topic or board you are looking for appears to be either missing or off limits to you.
                                                                           Back"

Which for me on my site it isn't a big deal as I only have two protected boards and the error message won't be a frequent occurrence.  But I can see how it could be annoying if there was lots of boards the person who clicked it couldn't access. Keep in mind too I'm a newb  and most stuff like this I learn as I go :) Even more reason to try change this though I guess.

Thanks!