PDA

View Full Version : Using a query in a plug-in


ChurchMedia
12-26-2006, 04:21 PM
I'm writing a hack and I can't figure out how to query a table and then use the data in a plug-in. I get this error:

Fatal error: Call to a member function on a non-object in /home/xxx/xxxx/forum/includes/class_postbit.php(268) : eval()'d code

Here is my plug-in code at postbit_display_start:

$info = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "secretsanta");
$usinfo = $db->fetch_array($info);
$uid = $usinfo['userid'];
$gave = $usinfo['gave'];
$received = $usinfo['received'];

if (!$this->post['uid'] = '') {
$santa = "<div align=\"center\"> <a href=\"giftexchange.php\"><img src=\"images/giftexchange/sm_secret_santa.gif\" border=\"0\" alt=\"$post[username] is a Secret Santa!\"></a></div>";
}

Any help is appreciated! :)

Guest190829
12-26-2006, 06:28 PM
I'm writing a hack and I can't figure out how to query a table and then use the data in a plug-in. I get this error:



Here is my plug-in code at postbit_display_start:

$info = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "secretsanta");
$usinfo = $db->fetch_array($info);
$uid = $usinfo['userid'];
$gave = $usinfo['gave'];
$received = $usinfo['received'];

if (!$this->post['uid'] = '') {
$santa = "<div align=\"center\"> <a href=\"giftexchange.php\"><img src=\"images/giftexchange/sm_secret_santa.gif\" border=\"0\" alt=\"$post[username] is a Secret Santa!\"></a></div>";
}Any help is appreciated! :)


Since it is inside a class use:


$this->registry->db->query_read()

Instead of $db->query_read()

Also, that code looks like it runs a query for every post, which I don't suggest doing.