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

  • Home
  • SEARCH
  • 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 7013247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:21:43+00:00 2026-05-27T22:21:43+00:00

I need some help. I am working on a backend of a website and

  • 0

I need some help. I am working on a backend of a website and I want to create functions where I can re-use the same code instead of duplicating it.

So I will have certain “sections” that contain information, such as:

getQuickInfo

function getQuickInfo() {

echo '
<div class="portlet">
        <div class="portlet-header">
            <h4>Quick Info</h4>
        </div>

        <div class="portlet-content">
            <table cellspacing="0" class="info_table">
                <tbody>
                    <tr>
                        <td class="value">'.getCount("total_users").'</td>
                        <td class="full">Total Users</td>
                    </tr>
                    <tr>
                        <td class="value">'.getCount("count_open_requests").'</td>
                        <td class="full">Open Support Requests</td>
                    </tr>
                </tbody>
            </table>
        </div>      
    </div>
';
}

Now I know I am approaching this the wrong way, that’s why I am posting this question. But that is just an example of a Quck Info section I would like to re-use on other pages, so I can sitck it wherever I want and just do getQuickInfo()

For this example, that function works fine. I would like suggestions on a better way to do it, and also for some other sections it won’t be that easy it will have some Mysql queries and grabbing information from a database, which I can’t store that within an echo.

How does everyone else accomplish stuff like this?

My main goal is to be able to output sections wherever I would like:

  • getQuickInfo()
  • getAdminNotes()
  • getSupportRequests()

etc.

Thanks!

  • 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-27T22:21:44+00:00Added an answer on May 27, 2026 at 10:21 pm

    Much as I am loathed to mix raw HTML with PHP code in templates, I know others disagree with me and this is one place where it might be a valid use.

    So you would create a file that looks like this:

    quickinfo.php

    <div class="portlet">
        <div class="portlet-header">
            <h4>Quick Info</h4>
        </div>
    
        <div class="portlet-content">
            <table cellspacing="0" class="info_table">
                <tbody>
                    <tr>
                        <td class="value"><?php echo getCount("total_users"); ?></td>
                        <td class="full">Total Users</td>
                    </tr>
                    <tr>
                        <td class="value"><?php echo getCount("count_open_requests"); ?></td>
                        <td class="full">Open Support Requests</td>
                    </tr>
                </tbody>
            </table>
        </div>      
    </div>
    

    …and in you main page, you can just do:

    include('quickinfo.php');
    

    You can easily adapt this to use the result of queries. You would simply perform the query in the main page, and assign the results to a named variable. Then in the template page you use the data in the named variable to generate the page. This means that you can use the same code to generate different results based on different queries – as long as the result are held in the same named variable.

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

Sidebar

Related Questions

Hey all i am in need of some help getting my code working correctly
Need some regular expressions help. So far I have my code working to allow
I am a Java programmer working with C++ code, and need some help with
I need some help with re-working the logic on this php code. What I'd
I am currently working on this website , and i need some help regarding
I need some help with types in Haskell... Here's the code I'm working on:
I am working with an array and need some help. I would like to
I really need some help in Regular Expressions, i'm working on a function like
I am currently working at a C# FTP Client and I need some help.
I'm working on a web application and need some help with a query. I'm

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.