If they are static variables, you could store them in the construct and refer to them like this:
function __construct()
{
$this->var1 = "data";
$this->var2 = "data";
$this->query = "select * from table";
}
function getVar1()
{
return $this->var1;
}
function getVar2()
{
return $this->var2;
}
// below has not been tested, but it should give you an idea
function getResults()
{
//load db lib
$q = $this->query($this->query);
if($q->num_rows() == 0)
return false;
return $q->result_object();
}
Or you could have private functions that you refer to in all of your functions.
private function nameQuery()
{
// return data
}
function getName()
{
return $this->nameQuery();
}
I have updated my original post with a revised version of the code you updated your posted with.
The first return you had in your details function will just return that and ignore the rest of the function.
You want to return the data retrieved from the uploadsQuery function, so you need to return that data in that function.
Then you want to store that data into your $data variable as seen in the details function, to be passed into the parse_variables function.
I can't say this works for sure, but it'll give you a push in the right direction
private function uploadsQuery() {
$member_id = $this->EE->session->userdata('member_id');
$sql = "
SELECT COUNT(t.author_id) AS current_uploads, c.upload_total AS upload_total
FROM exp_competition_purchase_upload_total AS c
LEFT JOIN exp_channel_titles AS t ON c.member_id = t.author_id AND t.channel_id = '4'
WHERE c.member_id = $member_id
";
$query = $this->EE->db->query($sql);
if($query->num_rows() == 0) // no data retrieved from table, return false
return false;
return $query->result_array(); // return this data, to be used in your other function
}
public function details() {
$data = $this->uploadsQuery(); // storing the data that was returned from the uploadsQuery function
if(!$data)
return false; // no data to pass into parse_variables below, so just return false
return $this->EE->TMPL->parse_variables( $this->EE->TMPL->tagdata, $data );
}