Jump to content

print class variable high up the page


isedeasy

Recommended Posts

I have a class that I created, halfway down my page I call a function from the class which prints some code and also changes a variable inside the class.

 

It's a search class basically it prints out the search results and saves the total amount of results into the variable.

 

I want to display the amount of results above the results like so:-

 

echo $Search->results;

$Search->GetResults('foo');

 

The problem is that $Search->results will be equal to NULL until the variable is updated in the function GetResults.

 

Hope that makes sense, am I going about this wrong?

Link to comment
Share on other sites

why not just print $this->results inside your getResults function before it prints the other stuff? Alternatively, you could have your getResults function return a string with the output instead of printing it. This is probably the better option. Then you can do

$str = $Search->GetResults('foo');
$res = $Search->results;

 

and use these variables whenever you need, instead of being forced to use the output when you call them.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.