Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 327335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:23:33+00:00 2026-05-12T09:23:33+00:00

I have a class designated for a certain site. In that site I have

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:23:34+00:00Added an answer on May 12, 2026 at 9:23 am

    It’s a good practice. Personally, I use the following template “engine”:

    <?php
    class Template{
        static function show($path, $arg = NULL){
            include "templates/$path.php";
        }
    
        static function get($path, $arg = NULL){
            ob_start();
            self::show($path, $info);
            $block = ob_get_contents();
            ob_end_clean();
            return $block;
        }
    }
    

    In your case the template would be like this:

    <?php
    echo '<h1>'.$arg['user']['userName'].'</h1>'; 
    if($arg['showDesc']){
      echo '<div>'.$arg['user']['description'].'</div>'; 
    }
    ?>
    

    You could unpack the array with the template arguments, but I prefer to keep it all in one place, so the code is less confusing. (You always know what is coming from the input, and what’s defined in the template this way. To keep things shorter, you might use $_ instead of $arg too.) For a small example like this, the benefit is not obvious, but for larger templates it save a lot of variable manipulation, as you can use PHP’s own templating abilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I know, any class that is designated to have subclasses should be declared
I have a helper class designed to get data from Core Data and pass
I have some C# class libraries, that were designed without taking into account things
I have general question about designated initializer. I have a some class and from
I have certain classes that have common feature - class factory that I need
I have my view controller class MyVC extending from UIViewController class. In the designated
I have a C++ program that will read in data from a binary file
I have class method that returns a list of employees that I can iterate
I have class A: public class ClassA<T> Class B derives from A: public class
I have class with a member function that takes a default argument. struct Class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.