Page 1 of 1

Adding a seperate sql query using addtional table in same database.

Posted: Sat Sep 08, 2007 4:19 pm
by kimartist
I'm trying to pull a category list from the same database and I keep receiving an error.

Here is what my smarty tag says:

global $gCms;
global $db;

$vars = $gCms->variables;

$q= "SELECT zen_categories_name  FROM zen_categories_description ASC";
$dbresult = $db->Execute($q);
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."";
}

if ($dbresult > 0) {
  $row = $dbresult->FetchRow();
  echo $row['categories_name'];
}

This is the error I'm getting:

Fatal error: Call to a member function on a non-object in /usr/home/sites/XXXXXXXXXXXXXXXXX/web/lib/content.functions.php(669) : eval()'d code on line 7

Now matter how I change the sql etc.
Hope someone can help.
I need to be able to do this in a few different sites.
Thanks in advance.
Kim

Re: Adding a seperate sql query using addtional table in same database.

Posted: Sat Sep 08, 2007 4:48 pm
by calguy1000
$db isn't a global anymore (not for a long time)...
and in 2.0, $gCms won't be either

use this:

Code: Select all

$db =& $gCms->GetDb();
$variables =& $gCms->variables;

Re: Adding a seperate sql query using addtional table in same database.

Posted: Sat Sep 08, 2007 7:36 pm
by kimartist
Okay, this is what we have now... but it is still giving us a Fatal Error.
Any other suggestions??

$db =& $gCms->GetDb();
$variables =& $gCms->variables;

$q= "SELECT zen_categories_name  FROM zen_categories_description ASC";
$dbresult = $db->Execute($q);
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."";
}

if ($dbresult > 0) {
  $row = $dbresult->FetchRow();
  echo $row['categories_name'];
}

Re: Adding a seperate sql query using addtional table in same database.

Posted: Sat Sep 08, 2007 9:46 pm
by tgmayfield
Please paste your entire plugin and the error result you get. Should be able to help from there. If that _is_ your entire plugin, re-add "global $gCms" to the top.

Re: Adding a seperate sql query using addtional table in same database.

Posted: Sat Sep 08, 2007 10:26 pm
by kimartist
Thank you very much...it worked like a charm....