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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
kimartist
New Member
New Member
Posts: 3
Joined: Sat Sep 08, 2007 4:06 pm

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post 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;
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
kimartist
New Member
New Member
Posts: 3
Joined: Sat Sep 08, 2007 4:06 pm

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

Post 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'];
}
tgmayfield
Forum Members
Forum Members
Posts: 11
Joined: Tue Apr 24, 2007 5:51 pm

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

Post 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.
kimartist
New Member
New Member
Posts: 3
Joined: Sat Sep 08, 2007 4:06 pm

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

Post by kimartist »

Thank you very much...it worked like a charm....
Post Reply

Return to “CMSMS Core”