News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Function name must be a string $smcFunc issue

Started by Eric B, July 08, 2010, 09:10:43 AM

Previous topic - Next topic

Eric B

Trying to use a function where I get some info from the DB for a mod I have. I keep getting function name must be a string on the line with
$result = $smcFunc['db_query']('', '




// Load the settings...
require_once(dirname(__FILE__) . '/Settings.php');
require_once(dirname(__FILE__) . '/SSI.php');

//Load the sources
require_once($sourcedir . '/QueryString.php');
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Errors.php');
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Security.php');
require_once($sourcedir . '/Subs-Portal.php');

loadDatabase();
loadSession();

// Register an error handler.
set_error_handler('error_handler');

function chatOnlineUsers(){
        global $smcFunc;

$userIDs = array();
$result = $smcFunc['db_query']('', '
SELECT userID
FROM {db_prefix}ajaxchat_online WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)' ,
  array()
);
while($row = $smcFunc['db_fetch_assoc']($result)) {
array_push($userIDs, $row['userID']);
}
$smcFunc['db_free_result']($result);
return array_unique($userIDs);
}


Any thoughts? Its probably something simple that I am overlooking.

CapadY

Add in the very begin of the function you create to call the queryfunction:

"global $smcFunc;"

so, for instance:


function MyNewFunction()
{
global $smcFunc;

bla bla bla your code;
}


Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Eric B

I have it there right as I start my first function.

function chatOnlineUsers(){
        global $smcFunc;
   
   $userIDs = array();
   $result = $smcFunc['db_query']('', '
      SELECT userID
         FROM {db_prefix}ajaxchat_online   WHERE NOW() <= DATE_ADD(dateTime, interval 2 MINUTE)' ,
     array()
   );
   while($row = $smcFunc['db_fetch_assoc']($result)) {
      array_push($userIDs, $row['userID']);
      }
   $smcFunc['db_free_result']($result);
   return array_unique($userIDs);
}

CapadY

The file where the "ChatOnlineUsers" function in is, is it made a part of SMF ? is it included ? (mostly done in root/index.php)
Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Advertisement: