9 Replies - 627 Views - Last Post: 25 March 2013 - 01:13 PM Rate Topic: -----

#1 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Constant Call to member function on non object.

Posted 25 March 2013 - 12:05 AM

	function GetForums()
	{
	global $con;
	$qry ="SELECT * FROM forums WHERE enabled = '1' AND 'category' = ".$category." ";

        $result = mysqli_query($con,$qry)
        or die("Error: ".mysqli_error($con));

        while($row = mysqli_fetch_array($result))
        {
        echo $row['title'];
        }
}

	function GetCategories()
	{
		global $con;
		$qry = "SELECT * FROM forum_categories WHERE enabled = '1' ORDER BY 'order' ASC";
		
		$result = mysqli_query($con,$qry)
		or die("Error: ".mysqli_error($con));
		
		while($row = mysqli_fetch_array($result))
	{
$category = $row['id'];
	echo "<div class='category'>".$row['title']."".$fgmembersite->GetForums()."</div> ";
	
        }
}


Trying to get $fgmembersite->GetForums() to pull up the forums that match the criteria for where they are. I am constantly getting the call to member object; I'm not sure as to why. $con is defined. It pulls the categories just fine, but when I add the the forums it flips a finger my way. Any help here is appreciated.

This post has been edited by DoxramosPS: 25 March 2013 - 12:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Constant Call to member function on non object.

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3191
  • View blog
  • Posts: 10,685
  • Joined: 12-December 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 12:36 AM

Where is $fgmembersite instantiated? And is GetForums a member (a method) of its class, rather than a simple function?
Was This Post Helpful? 0
  • +
  • -

#3 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 10:16 AM

  
function InitDB($host,$uname,$pwd,$database,$tablename)
    {
        $this->db_host  = $host;
        $this->username = $uname;
        $this->pwd  = $pwd;
        $this->database  = $database;
        $this->tablename = $tablename;
        $this->forumTable = forums;
        
    }


I think my issue may lie in here; I'll be taking a look to see what I can do to fix it up and post back when I return.

And the GetForums() is a simple function; wasn't really going for making it a member of any class. Still learning how it all works.
 function DoxFunction()
    {
        $this->sitename = 'doxramos.org';
        $this->rand_key = '0iQx5oBk66oVZep';
    }
    
    function InitDB($host,$uname,$pwd,$database,$tablename)
    {
        $this->db_host  = $host;
        $this->username = $uname;
        $this->pwd  = $pwd;
        $this->database  = $database;
        $this->tablename = $tablename;
        $this->forumTable = forums;
        
    }
    function SetAdminEmail($email)
    {
        $this->admin_email = $email;
    }
    
    function SetWebsiteName($sitename)
    {
        $this->sitename = $sitename;
    }
    
    function SetRandomKey($key)
    {
        $this->rand_key = $key;
    }


And there's the Instantiation.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,421
  • Joined: 23-August 08

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 10:31 AM

Well, if this is true

Quote

And the GetForums() is a simple function; wasn't really going for making it a member of any class.


Why are you trying call GetForums() as if it's a member function of the class represented by $fgmembersite?

This code

$fgmembersite->GetForums()
says "Call the GetForums method of the class that $fgmembersite represents" and therefore makes no sense if it's a standalone function.
Was This Post Helpful? 0
  • +
  • -

#5 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 11:09 AM

I've redone the forum calls and such trying to figure it out fully. I think I understand how it works now, but it's begging to differ, So we now have my DoxFunction Class. The GetForums Function and the Initialization Function.
Class:
class DoxFunction
{
    var $admin_email;
    var $from_address;
    
    var $username;
    var $pwd;
    var $database;
    var $tablename;
    var $connection;
    var $rand_key;
    
    var $error_message;


Initialization:
 function InitDB($host,$uname,$pwd,$database,$tablename)
    {
        $this->db_host  = $host;
        $this->username = $uname;
        $this->pwd  = $pwd;
        $this->database  = $database;
        $this->tablename = $tablename;
        
    }


Which is then passed through:
$DoxFunction->InitDB(/*hostname*/'****',
		     /*username*/'****',
		     /*password*/'****',
		     /*database name*/'****',
		     /*table name*/'forums');


And Finally the actual Function to pull the forums.
  function  GetForums()
   {
	$qry = "SELECT * FROM $this->tablename WHERE enabled='1'";
   
	$result = mysqli_query($con,$qry);
	foreach ($result as $row)
   	{
   	print $row->title;
   	}
   }


Where GetForums is a $DoxFunction Class. If it seems like I'm off on anything please let me know because now it's telling me.
unexpected $end, expecting T_FUNCTION 


Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,421
  • Joined: 23-August 08

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 11:33 AM

Unexpected end means you're probably missing a closing brace.

Think your errors through!
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3191
  • View blog
  • Posts: 10,685
  • Joined: 12-December 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 11:38 AM

Quote

Where GetForums is a $DoxFunction Class.

Your class is named DoxFunction, so where is the variable $DoxFunction instantiated? And how is GetForums an (I assume you mean instance of..) the DoxFunction class?

Is InitDB a method within your class DoxFunction? In which case, there is no variable named db_host.

And GetForums is unrelated to any of the other code(?).

Sorry, but I can't see that you have implemented this correctly.

This post has been edited by andrewsw: 25 March 2013 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#8 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 11:42 AM

Sorry The unexpected $end was the class bracket.
As for everything else; I'm starting to get to a loss of where to go from here.
I get the same error; I can even have.
function GetForums
{
     $qry = "SELECT * FROM forums WHERE enabled = 1";
     print $qry;
}


Then run
<?= $DoxFunctions->GetForums(); ?> 


On my page and still get the call to member function error. I thought it might be SQL based, but it's looking like it's not at this point.
Was This Post Helpful? 0
  • +
  • -

#9 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 01:01 PM

Off topic for this here right now, but I'm trying to get it to run in the page itself then try to figure out what I'm doing wrong with the functions. Noticed another issue that's a major kick.
						$qry = "SELECT * FROM forums WHERE enabled = '1' AND category = '".$category."'";


$category is defined and when I run the Query it's running correctly in each place, but at the moment it's running say
SELECT * FROM forums WHERE enabled= = '1' AND category = '3'

Everywhere past three it's returning the result, so say category 4 is Help and Support and Category 3 is Fun and Games. Everything from Fun and Games will be in Help and Support as well.
Was This Post Helpful? 0
  • +
  • -

#10 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 156
  • Joined: 07-October 12

Re: Constant Call to member function on non object.

Posted 25 March 2013 - 01:13 PM

Tried Adding.
		if (mysqli_num_rows($result)=='0')


Unfortunately with the if else statement it still didn't help. :( It looks as if if the actual query is empty it just returns a the previous categories results till there's a match.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1