Previous Thread
Next Thread
Print Thread
Hop To
Anonymous
Unregistered
Anonymous
Unregistered
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

Anonymous
Unregistered
Anonymous
Unregistered
Are you using the full path (not url) to your threads installation? It looks like its not finding main.inc.php thus all the queries fail.

Josh
www.joshuapettit.com
ThreadsDev.com Administrator | InfoPop Community Moderator
Register to see my How To/Site Help Library Forum at ThreadsDev.com.
My threads 'tweaking' abilities are for hire for upgrades, tweaks and modifications.

Anonymous
Unregistered
Anonymous
Unregistered
Yeah, the path is right. When I had the path wrong I got an error about the 'html' class not being valid. (that class is defined in main.inc.php I believe)


--
Gary

--
Gary McNickle

Anonymous
Unregistered
Anonymous
Unregistered
You should be able to use the addon in a PHP page. However the actual SQL error is being masked. If you've can view the MySQL error log from your admin menu (if you are on 6.2) that should show you the real error and give more clues.

<img border="0" title="" alt="[Wink]" src="images/icons/wink.gif" />

Josh
www.joshuapettit.com
ThreadsDev.com Administrator | InfoPop Community Moderator
Register to see my How To/Site Help Library Forum at ThreadsDev.com.
My threads 'tweaking' abilities are for hire for upgrades, tweaks and modifications.

Anonymous
Unregistered
Anonymous
Unregistered
Do you have other addons on the same page?

--
UBBDesign.com: Custom web development & UBB â„¢ customization.

Anonymous
Unregistered
Anonymous
Unregistered
No, that's the only addon i'm using.

--
Gary McNickle


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
Is UBB.threads still going?
by Aaron101 - 04/01/2022 8:18 AM
Who's Online Now
4 members (Nightcrawler, Outdoorking, Ruben, 1 invisible), 872 guests, and 274 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)