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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:51:59+00:00 2026-06-13T13:51:59+00:00

This is my second post today because I’m very new at OOP in PHP,

  • 0

This is my second post today because I’m very new at OOP in PHP, so bear with me if it’s a silly question…

I’ve created a beautiful class that I want to be able to use with my “JOB” objects that includes being able to use this single object to pull data from many tables so the end user sees relevant data. For instance, in my class, I have:

public function showProjectManager() {
    $q = "SELECT m.name FROM " . jJOBS . " AS j JOIN " . jMEI . " AS m ON m.uid = j.mei WHERE id = " . $this->id;
    $r = $this->_dblink->query($q);
    $row = $r->fetch_assoc();
    return $row['name'];
}

because the data stored in the jJOBS table is merely a number that references an id in another table. There are several pieces of data like this stored in the main jJOBS table.

So, in another section of code there is a dropdown box that lets the user select a specific “JOB” and using an AJAX call I want to display the data from that JOB. What I’m trying to do is create a JOB object (which includes the showProjectManager method), read all the properties from a database using mysqli_fetch_object and then call the showProjectManager method, like this:

    $disp = new Job();
    $q = "SELECT * FROM " . jJOBS . " WHERE id = " . $job_id;
    $r = $jobsdb->query($q);
    $disp = $r->fetch_object();
    $zList .= "<li><span class='smLabels l'>Project Manager :</span>\n<span class='smText r'>" . $disp->showProjectManager() . "</span></li>";

But whenever I fetch the object from the DB, the $disp object reverts back to stdClass. How can I maintain the proper class and access the values I need from the DB? Everything I have read on the subject calls for the use of a DataMapper which seems incredibly complex, especially for this scenario.

  • 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-13T13:52:00+00:00Added an answer on June 13, 2026 at 1:52 pm

    Easiest approach is to pass a class name to fetch_object, like so:

    $q = "SELECT * FROM " . jJOBS . " WHERE id = " . $job_id;
    $r = $jobsdb->query($q);
    $disp = $r->fetch_object("Job");
    

    Per the documentation, this will create $disp as an object of type Job with all its fields filled out, then call the Job constructor.

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

Sidebar

Related Questions

I'm using jQuery. This is my second post to make my old question more
It's my second ignorant question for today, this one even more ignorant than the
This is my second post because i also can't find the solution so I
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
First, a thank you in advance. Second, this is my first post so apologies
This is my second attempt at this question . I made a mess of
This is my second question about clicking buttons in JavaScript but this one I'm
This is my second question on Bamboo ( My First One ). My understanding
this is my second post on the website. Of all other sites i tried,
Unfortunately, this is my second post in as many days. So the application worked

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.