TinyPortal

Development => Block Codes => Topic started by: evilicy on August 04, 2008, 01:15:24 AM

Title: Random Topic Link
Post by: evilicy on August 04, 2008, 01:15:24 AM
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
Title: Re: Random Topic Link
Post by: Ianedres on August 04, 2008, 01:58:52 AM
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.
Title: Re: Random Topic Link
Post by: evilicy on August 04, 2008, 04:28:40 AM
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!