Cep Posted March 29, 2006 Share Posted March 29, 2006 I am trying calling a function from another script but everytime I run it, I get the following error.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Fatal error: Call to a member function on a non-object in /wbbrpg_functions.php on line 5[/quote]The call is,[code]$n_tile = rpg_gettile($nid);[/code]Where $nid is an integer.and the function that causes the error is,[code]function rpg_gettile($tile_id) { $type = $db->query_first("SELECT * FROM bb1_wbbrpg_location_types WHERE typeid = ".$tile_id.""); $tile_name = $type['name']; $tile_img = $type['image']; $tile_magic = $type['magic']; $tile_fly = $type['fly']; $tile_walk = $type['walk']; $tile_sail = $type['sail']; $tile_tunnel = $type['tunnel']; $tile_array = array($tile_id, $tile_name, $tile_img, $tile_magic, $tile_fly, $tile_walk, $tile_sail, $tile_tunnel); return $tile_array;}[/code]Line 5 is the SQL statement Quote Link to comment Share on other sites More sharing options...
lead2gold Posted March 29, 2006 Share Posted March 29, 2006 the error is probably: $db->...is the object $db declared somewhere previously using the new command?is $db out of the scope of how your using it?you might have to write this within you function "rpg_gettile"global $db; Quote Link to comment Share on other sites More sharing options...
Barand Posted March 29, 2006 Share Posted March 29, 2006 variables inside a function are "local" to that function. $db is not defined inside the function and has a null value.If you want to use $db inside the function either- declare it as global in the function[code]function rpg_gettile($nid) { global $db; ## rest of function code}[/code]or, better, pass it an an argument to the function[code]function rpg_gettile($db, $nid) { ## rest of function code}$n_tile = rpg_gettile($db, $nid); // pass $db to function[/code] Quote Link to comment Share on other sites More sharing options...
Cep Posted March 29, 2006 Author Share Posted March 29, 2006 Thanks guys I didnt spot that I had but that there :) cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.