PDA

View Full Version : Option Data From Table


SorentoUltimate
09-17-2009, 07:30 AM
Hello, i writeing a new addon and i have a problem.
i try to load data from a ta table for an option but i cannot make it !!!!

Option Code

select:eval
require_once(DIR . '/includes/functions_colors.php');
$options = fetch_colors_options_array();_

functions_colors.php

<?php

error_reporting(E_ALL & ~E_NOTICE);

// ###################### Fetch Colors as Options #######################
// Return Colors Options Array
function fetch_colors_options_array()
{

global $vbulletin;
$out = array();

// fetch Colors
$getcolors = $db->query_read("
SELECT colorid, colorname
FROM `" . TABLE_PREFIX . "colors`
");

echo 'After Get';

while ($colorrow = $db->fetch_array($getcolors))
{
$out["$colorrow[colorid]"] = "$colorrow[colorname]";
}

return $out;

}

?>
_

Error :

Fatal error: Call to a member function on a non-object in /......./......./......./......./forum/includes/functions_colors.php on line 14

Lynne
09-17-2009, 05:54 PM
Did you include global.php or init.php in your main file? If not, $db->query_read is not valid since it is a vbulletin thing.

SorentoUltimate
09-17-2009, 06:28 PM
no i don't include,

need to include global.php or init.php to functions_colors.php or to plugin i call function ???

Lynne
09-17-2009, 06:55 PM
Well, or you need to use standard php language to access the database.

SorentoUltimate
09-17-2009, 06:59 PM
Well, or you need to use standard php language to access the database.

Where to put global.php and(or) init.php ??

Lynne
09-17-2009, 07:04 PM
Well, you need to include it before you make any database calls. So, in either file I would think is fine. Depends on if you will need it again or not.

SorentoUltimate
09-17-2009, 07:06 PM
Well, you need to include it before you make any database calls. So, in either file I would think is fine. Depends on if you will need it again or not.

ok, thanks
i try and if i have any more problem i write it

--------------- Added 1253218729 at 1253218729 ---------------

i put require_once('./global.php'); at option code

and now the option code are

select:eval
require_once('./global.php');
require_once(DIR . '/includes/functions_colors.php');
$options = fetch_colors_options_array();

but now the error are :

Fatal error: Call to a member function on a non-object in /......./......./......./......./forum/global.php on line 242