General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 24th, 2003, 03:25 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
ERROR calling a function from within another...

Hello all, a quasi-newbie here.

I get this error message: Fatal error: "Call to a member function on a non-object in /home/cmcd/public_html/plcdemo00/phpZipLocator.php on line 119"

The problem came up when I had to wrap sections of my script up within fuctions so that I could add error handling to the form. The problematic portion of the script follows:

(RETURNS INSERTED TO PRESERVE FORUM FORMAT)

PHP Code:
function process_form()
{

global 
$strSex$strSeeks$within$myzip$strCountry,
$strPhotos$strSearchmap$strSaveLev,
$strSearchName;
global 
$FirstPass$Errchk$userCook;
global 
$PHP_SELF;

//require_once("db_mysql.inc");
//require_once("phpZipLocator.php");

// Calculate date based on age
$pdate date("Y"); 
$sYear = ($pdate $strStartDate);
$eYear = ($pdate $strEndDate);

$countries implode("_"$strCountry);

// create a query string to be stored in db
if (in_array ("500"$strCountry)) {

//zip code stuff
require ("db_mysql.inc");
require (
"phpZipLocator.php");

$db = new db_sql;
global 
$db;
$zipLoc = new zipLocator;
//global $zipLoc;

$zipOne $myzip;
global 
$zipOne;

$radius $within;
global 
$radius;
$zipArray = ($zipLoc->inradius($zipOne,$radius));
//global $zipArray;

$Zips implode("_"$zipArray);
global 
$Zips;


    
$strSearchVars $strSex.",".$strSeeks.",".$eYear.",".$sYear
.",".$countries.",".$strPom.",".$Zips;

    } else {
    
    
$strSearchVars $strSex.",".$strSeeks.",".$eYear.",".$sYear
.",".$countries.",".$strPom.",NoZip";
    




Here is the function that is being called from the include("phpZipLocator.php")
PHP Code:
function inradius($zip,$radius)
    {
        global 
$db;
        global 
$zip;
        global 
$radius;
        
$query="SELECT * FROM zipData WHERE zipcode='$zip'";
        
$db->query($query);

        if(
$db->affected_rows()<>0) {
            
$db->next_record();
            
$lat=$db->f("lat");
            
$lon=$db->f("lon");
            
$query="SELECT zipcode FROM zipData WHERE (POW((69.1*
(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),
\"2\"))<($radius*$radius) "
;
            
$db->query($query);
            if(
$db->affected_rows()<>0) {
                while(
$db->next_record()) {
                    
$zipArray[$i]=$db->f("zipcode");
                    
$i++;
                }
            }
        }else{
            return 
"FALSE";
        }
     return 
$zipArray;
    } 
// end func

// end class 


Any help would be greatly appreciated!
__________________
$mybrain = "mush";
-------------------------------------------
http://www.loftsboston.com
http://www.gregdawsondesign.com

Last edited by Mojoman : June 24th, 2003 at 03:31 PM.

Reply With Quote
  #2  
Old June 24th, 2003, 03:34 PM
_rainbow_ _rainbow_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Lj, Slovenia
Posts: 27 _rainbow_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 28 sec
Reputation Power: 0
Would be very usefull if you told wich line is the 119th.


Reply With Quote
  #3  
Old June 24th, 2003, 03:45 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
Oh yeah!

Line 119:

$radius;
$query="SELECT * FROM zipData WHERE zipcode='$zip'";
$db->query($query);

Reply With Quote
  #4  
Old June 24th, 2003, 06:00 PM
_rainbow_ _rainbow_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Lj, Slovenia
Posts: 27 _rainbow_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 28 sec
Reputation Power: 0
If you replace these two lines

PHP Code:
 $db*=*new*db_sql;
global*$db


with

PHP Code:
 global*$db;
$db*=*new*db_sql


it should work just fine.

Reply With Quote
  #5  
Old June 24th, 2003, 07:38 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
thanx, but it didn't work! sigh!

Reply With Quote
  #6  
Old June 25th, 2003, 06:37 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Ok - are all these functions wrapped inside a class? being - the function where you are creating the object, is that actually an operation of a class? Have you tried using the scope::modifier?

Another thing is - you don't need the global $blah; on the $db scalar if it is called within that function.

You are passing the $radius and $zip to the function/method - so also there is no need to use global. If these are all operations/methods - you can avoid using global altogether in your code - ie:
PHP Code:
class some_class
{
    
/*-----------------------------------
    Class Attributes
    -----------------------------------*/
    
var $db;
    var 
$radius;
    var 
$zip;
    
/*-----------------------------------
    Class Constructor
    -----------------------------------*/
    
function some_class()
    {
        
/*-----------------------------------
        Bind Attributes
        -----------------------------------*/
        
$this->db = new database_connection();
        
$this->radious /* Some Value */;
        
$this->zip /* Some Value */;
        
/*-----------------------------------
        Do Something
        -----------------------------------*/
        
$this->do_something();
    }
    
/*-----------------------------------
    Method To Do Something
    -----------------------------------*/
    
function do_somthing()
    {
        
/* Use the created object */
        
$this->db->query"SELECT blah FROM blah" );
        
/* Or - use the scope modifier */
        
database_connection::query"SELECT blah FROM blah" );
    }

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > ERROR calling a function from within another...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway