Topic: Recent Discussions on Frontpages
Okay, I'm not a coder at all but I took the time to create some code for "recent discussions" on front pages:
I used it in a seperate file like _recentdiscussions.php which I included then into the CMS:
<?
$MYSQL_HOST = 'localhost';
$MYSQL_USER = '';
$MYSQL_PASSWORD = '';
$MYSQL_DATABASE = '';
$mySQLconerror = "<h1>mySQL server died unexpectly</h1><h3>There was an internal error processing your request!</h3>Click <a href='javascript:location.href=location.href'>refresh</a> to resubmit the information.<br>If the error persists contact your system administrator or the support team.</h3>";
$mySQLdberror = "<h1>mySQL server internal error</h1><h3>Could not select the database! The database might be deleted or in error code.</h3>Click <a href='javascript:location.href=location.href'>refresh</a> to resubmit the information.<br>If the error persists contact your system administrator or the support team.</h3>";
function ExecuteSQL($query,$db_conn) {
$result = mysql_query($query,$db_conn);
if (mysql_errno() != "0") {
echo "<div class='error'><br>mySQL ERROR # ".mysql_errno()." <br> ".mysql_error()."<br><br><br><button hidefocus onClick='history.back(-1)' class='menu1'>Back</button><br><br></div>\n";
die();
}
else {
return $result;
}
}
$numberOfPosts = 5;
$numberOfCharacters = 85;
$connection = @mysql_connect("$MYSQL_HOST", "$MYSQL_USER", "$MYSQL_PASSWORD") or die("$mySQLconerror");
$db = @mysql_select_db("$MYSQL_DATABASE", $connection) or die("$mySQLdberror");
$sql = "SELECT id,poster,message,posted,topic_id FROM posts ORDER by posted DESC LIMIT 0,".$numberOfPosts;
$result = ExecuteSQL($sql,$connection);
$connection1 = @mysql_connect("$MYSQL_HOST", "$MYSQL_USER", "$MYSQL_PASSWORD") or die("$mySQLconerror");
$db1 = @mysql_select_db("$MYSQL_DATABASE", $connection1) or die("$mySQLdberror");
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT subject FROM topics WHERE id='".$row['topic_id']."'";
$res = ExecuteSQL($sql,$connection);
$tmp = mysql_fetch_array($res);
$topic = $tmp["subject"];
$thread = $row["id"];
$myname = $row["poster"];
$ctext = $row["message"];
$ctext = ereg_replace("^(.{1,$numberOfCharacters})[ .,].*", "\\1", $ctext);
$myname = str_replace("<","",$myname);
$myname = str_replace(">","",$myname);
$ctext = strip_tags($ctext);
$topic=substr($topic,0,25)."...";
/*
$sql1 = "SELECT threadid,forumid FROM itaf_thread where threadid='{$thread}' limit 0,1";
$result1 = ExecuteSQL($sql1,$connection1);
while ($row1 = mysql_fetch_array($result1)) {
$forum = $row1["forumid"];
}
*/
$output = "<a href=\"/forum/viewtopic.php?pid={$thread}#{$thread}\"><b>{$topic}</b></a><br><b>{$myname} says:</b> <i>{$ctext}...</i>";
$output = str_replace("\n","",$output);
$output = str_replace("\r","",$output);
print $output."<p>";
}
?>
The result can be seen here http://www.ppcw.net/
Oh yes, again - I have more or less no coding skills so the code above might be completely crap - feel free to improve and modify it... ;-)