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 8074009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:31:08+00:00 2026-06-05T14:31:08+00:00

This is the first time I’ll be making a PHP application that will have

  • 0

This is the first time I’ll be making a PHP application that will have many users accessing it so where as before I didn’t have to worry about loading speeds, I do now.

These are the ways I have thought of doing it but they all seem to be a bit “hack-ish” and I’m sure there is a better way.

For the index page I could have this:

<h1><?php $job->getTitle($id); ?></h1>
<p><?php $job->getDescription($id); ?></p>
<p><?php $job->getSomethingElse($id); ?></p>

And the class as:

function getTitle($id) {
    $query = "SELECT title FROM table WHERE id = $id";
    $result = $db->query($query);

    $row = $result->fetch_array(MYSQLI_ASSOC);
    echo $row['title'];
}

function getDescription($id) {
    $query = "SELECT description FROM table WHERE id = $id";
    $result = $db->query($query);

    $row = $result->fetch_array(MYSQLI_ASSOC);
    echo $row['description'];
}

etc…

Or I could have one function, call all the results to an array. Store them as a String and explode them as I need them.

My other idea was similar to above, except I do everything in the class and echo the html.

What is the best way in terms of speed to output what I want?

  • 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-06-05T14:31:10+00:00Added an answer on June 5, 2026 at 2:31 pm

    Jee, have You ever listened about the MVC (Model-View-Controller) design pattern?

    Though I do not want You to rewrite whole Your app, You still can get used to using of Models… By this (in very simple way) way You create a class Model that has a __construct($id) method that queries the DB to load all the necessary data and store them within a private/publi/protected (whatever makes You feel good) properties.

    Then You call these getXYZ() methods on that model that only returns it’s property values…

    Like this:

    class Article {
    private $title;
    private $description;
    private $somethingElse;

        public function __construct($id) {
            $query = "SELECT title, description, somethingElse FROM table WHERE id = $id";
            $result = $db->query($query);
    
            $row = $result->fetch_array(MYSQLI_ASSOC);
            $this->title = $row['title'];
            $this->description = $row['description'];
            $this->somethingElse = $row['somethingElse'];
        }
    
        public function getTitle() {
            return $this->title;
        }
    
        public function getDescription() {
            return $this->description;
        }
    
        public function getSomethingElse() {
            return $this->somethingElse;
        }
    

    That’s it… Just one query to retrieve all the data…

    In a case You want to also edit this model You can create also a setXYZ($value) methods that will set $this->XYZ = $value; and a save() method that will update this very concrete row in the database…

    These methods (get and set) are called getters and setters…

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

Sidebar

Related Questions

this is my first time posting here, I have a question which I have
This is my first time making a hash table. I'm trying to associate strings
I have two update panels at my ajax page. This is first time I'm
So here I have this first time app I'm working on. When I run
I have tableview that scroll vertically. My question is when first this view is
I am making a site in Russian language. This is first time, I am
This is first time that I work with json. I am trying to return
this is first time i'm develope paypal form , i have problem with shipping
This is my first time on StackOverflow though I read Coding Horror quite often.
This is the first time I'm creating an open-source project, and I've decided (based

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.