I have a class designated for a certain site. In that site I have different functions to retrieve data from the database and store that data into an array. I have other functions within the same class that take the data and format it into html and returns the html containing the data from the database.
For example...
function GetUserProfile($userID){
$query = 'SELECT * FROM users WHERE userID='.$userID;
.......
blah blah blah
.......
$user = mysqli->fetch_assoc();
return $user;
}
function FormatUserProfile($user, $showDesc = false){
$profile = '< h1 >'.$user['userName'].'< / h1 >';
if($showDesc){
$profile .= '< div >'.$user['description'].'< / div >';
}
return $profile;
}
...
So if i had a function to solely gather information, and another function to solely format that gathered information. Mainly because I will be showing the same data on different pages, but Different pages show different data, like a search would only bring up the users name, where as the users profile page would bring up the username and the description for example.
Is that good practice, or is there a better way to do this?