PDA

View Full Version : SQL query problem.


FlyingDutchman
09-16-2002, 06:58 PM
i have some problems :(
i have this script:

$threadz = $DB_site->query("SELECT title,originalforumid,threadid FROM thread WHERE forumid='5'");

if (!$DB_site->num_rows($threadz)) {
print '<br>No threads found.</b>';
} else {
while ($thread_info = $DB_site->fetch_array($threadz)) {
extract($thread_info);
$forumd = $DB_Site->query("SELECT title FROM forum WHERE forumid='$thread_info[originalforumid]'");
print '<br><b>'.$thread_info[title].'</b> - <a href="../postings.php?action=restore&threadid='.$thread_info[threadid].'&s='.$session[sessionhash].'">[restore]</a>'.$thread_info[originalforumid].'';
}
}

it's working o.k, except for 1 line:

$forumd = $DB_Site->query("SELECT title FROM forum WHERE forumid='$thread_info[originalforumid]'");

it just keeps on giving me this error:

Fatal error: Call to a member function on a non-object in c:\file-x.php on line 31

I've already asked Xenon for help, but he doesn't know what the problem is either...
Thanks for any help you can give me,


FlyingDutchman



P.S. originalforumid is from type smallint(5) unsigned if that possibly matters (guess not, but ok)

NTLDR
09-16-2002, 07:01 PM
Try adding before that line:

global $DB_site

FlyingDutchman
09-17-2002, 03:25 AM
i've tried already... didn't work?!?!?

Velocd
09-17-2002, 05:23 AM
Did you insure that global.php is being included in the file file-x.php?

Chances are the non-member object it's referring to is $DB_site.

If it is included at the top of the file, then try this instead:

Replace:

$forumd = $DB_Site->query("SELECT title FROM forum WHERE forumid='$thread_info[originalforumid]'");


With:

$forumd = $DB_Site->query_first("SELECT title FROM forum WHERE forumid='$thread_info[originalforumid]'");


And I'm just curious by the way, but what is the point of this query:
$forumd = $DB_Site->query("SELECT title FROM forum WHERE forumid='$thread_info[originalforumid]'");


It's usually never good to put a query inside a while loop, as it will generate many many queries..

FlyingDutchman
09-17-2002, 12:31 PM
it's for my (upcoming) recycle bin hack, it will get a listing of all threads that are in the recycle bin and it will also show the original forum title (which -the id- is saved in the row 'originalforumid' in the table 'thread'

this piece of code is for the admin CP...
i can't really move it out of the while loop, b/c the forumid variable ($thread_info[originalforumid]) is defined in the while loop...

of course i've required global.php and i've changed query to query_first also, but no luck :(


P.S. This code isn't really really needed for the hack, but i'd like to get it running this way, and just printing the forumid is kinda lame i think, the title suits better...

FlyingDutchman
09-17-2002, 01:11 PM
w00t, I guess all you guys are as stupid as me :D

the fix is: change $DB_Site to $DB_site, d0h ;)
i'm happy that i found out this typo myself :)