Reputation: 4152
I don't know if you're supposed to refer to them as "functions" but...
My when my add_record function is called, I want to re-use another function I have made which gets a list of team names from the database;
public function add_record($data){
$teamnames = function get_teamnames;
print_r($teamnames);
exit;
/*
$this->db->query('INSERT INTO reports(`date`,refereename, refereeteam, hometeam, homecaptain, awayteam) VALUES (
"'.strtotime($data['date']).'",
"'.$data['refereename'].'",
"'.$data['refereeteam'].'",
"'.$data['hometeam'].'",
"'.$data['captainname'].'",
"'.$data['awayteam'].'"
)');
*/
}
And here is my get_teamnames function (from within the same file)
public function get_teamnames(){
//Get team data from database, place into resource.
$teamsData = $this->db->query('SELECT * FROM teamnames ORDER BY teamname ASC');
// Array which we will return to the Slim router
$teams = array();
// PLace all the teams from the mysql resource into the array
while ($row = $teamsData->fetch_object()) {
$teams[] = $row;
}
// Return the teams array
return $teams;
}
The reason I want the list of teamnames available in my add_record function, is so that I can do some validation on the $data
and make sure that what's being submitted is only one of those team names stored in the database.
Upvotes: 1
Views: 1747
Reputation: 79024
Assuming these functions are in the same class and you are using an object of the class, just do:
$teamnames = $this->get_teamnames();
Upvotes: 2