Hi, I have a rather interesting problem.
Essentially, I am running a php based website, and on my main page, I want to show the last few posts on my ubbt forum. I've tried to call the ubbttopthreads.php file directly from within my main page php file, but there are several incompatibilites (i'm no php guru but these seem to be scope related linking issues).
In any case, to avoid all of that, I thought it would be easier to modify the ubbttopthreads script to be run from cron every few minutes, and output it's results to a textfile, which I could then easily read back in from my main page.
Only, it's not quite working... I'm getting the following error when I try to run the script...
[error]
SQL ERROR: Database error only visible to forum administrators
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/****/public_html/ubbthreads/mysql.inc.php on line 130
[/error]
Here is my modified script, if anyone can point out what I'm doing wrong, I would greatly appreciate it...
<?
/*
# UBB.threads, Version 6
# Official Release Date for UBB.threads Version6: 06/05/2002
# First version of UBB.threads created July 30, 1996 (by Rick Baker).
# This entire program is copyright Infopop Corporation, 2002.
# For more info on the UBB.threads and other Infopop
# Products/Services, visit:
http://www.infopop.com# Program Author: Rick Baker.
# You may not distribute this program in any manner, modified or otherwise,
# without the express, written written consent from Infopop Corporation.
# Note: if you modify ANY code within UBB.threads, we at Infopop Corporation
# cannot offer you support-- thus modify at your own peril <img border="0" title="" alt="[Smile]" src="images/icons/smile.gif" />
# ---------------------------------------------------------------------------
*/
// -------------------------------------------------
// Variables Section - Edit these to suit your needs
// Path to your main.inc.php script
$path = "<removed for security>";
// Top threads by "views" or by "replies"
$topthreads = "replies";
// Post age threshold. How many days old can a thread be and still make
// the list
$threadage = 7;
// Set this variable to the total number of threads that you wish to show
$totalthreads = 5;
// This varialbe will affect the way the thread is listed. Set this to none
// and it will only show the thread Subject, with a link pointing to the
// item on the board. Set it to "full" and it will show the body of the
// item below the subject. Set it to a number and it will show
// that many characters of the body with the subject clickable to read the
// full item.
$threadbody = 'none';
// The url to your UBB.threads installation
$forumurl = "http://www.toprpg.com/ubbthreads";
// Include the date when the news was posted
$includedate = "no";
// Include who it was posted by
$includewho = "no";
// You may need to change the unshift line to the path of your UBB.threads
// installation
// -----------------------------
// End of the variables section
require ("$path/main.inc.php");
// -------------------
// Setup the variables
$html = new html;
$date = $html -> get_date();
$date = $date - ($threadage * 86400);
$sort;
if ($topthreads == "views") {
$sort = "t1.B_Counter";
}
else {
$sort = "t1.B_Replies";
}
// --------------------------
// Let's grab the news items
$query = "
SELECT t1.B_Number,t1.B_Posted,t1.B_Last_Post,t2.B_Username,t1.B_Subject,t1.B_Body,t1.B_Main,t1.B_Replies,t1.B_Counter,t1.B_Board
FROM {$config['tbprefix']}Posts AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.B_Number = t1.B_Main
AND t1.B_Last_Post > '$date'
AND t1.B_PosterId = t2.U_Number
ORDER BY $sort DESC
LIMIT $totalthreads
";
$sth = $dbh -> do_query($query);
// ---------------------------
// echo out the starting html
$file = fopen("topthreads.txt", "wb");
fwrite($file, "<DL>");
// -----------------------
// Cycle through the posts
while ( list($Number,$Posted,$Last,$Username,$Subject,$Body,$Main,$Replies,$Counter,$Keyword) = $dbh -> fetch_array($sth)) {
// ---------------------------------
// Set up the variables for echoing
$date = $html -> convert_time($Posted);
if ($threadbody == "none") {
$Body = "";
$Subject = "<a href=\"$forumurl/showflat.php?Board=$Keyword&Number=$Number\">$Subject</a>";
}
if (ereg("[0123456789]",$threadbody)) {
$Body =substr($Body,0,$threadbody);
$Body .="...";
$Subject = "<a href=\"$forumurl/showflat.php?Board=$Keyword&Number=$Number\">$Subject</a>";
}
if ($includedate == "yes") {
$date = "<br>Posted on $date";
}
else {
$date = "";
}
if ($includewho == "yes") {
$Username = "<br>Posted by $Username";
}
else {
$Username = "";
}
// -------------------------------
// The actual HTML that is put out
$output_str = "<DT>
$Subject$date $Username<DD>$Body";
fwrite($file, $output_str);
// ---------------
// End of the HTML
}
fwrite($file, "</DL>");
$dbh -> finish_sth($sth);
fclose($file);
?>
--
Gary McNickle