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

The Archive Base Latest Questions

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

Model: class News { public $title; public $article; public $date; public $published; public $publisher;

  • 0

Model:

class News
{
    public $title;
    public $article;
    public $date;
    public $published;
    public $publisher;
    public $image;

    public static function getSingleArticle($id)
    {
        $query="SELECT *, date_format(date, '%D %M %Y') AS uk_date FROM news WHERE id=$id";
        return mysql_query($query);
    }
}

Controller:

public function editAction()
{
    $row=News::getSingleArticle($_GET['id']);

    $model=mysql_fetch_object($row);

    include('application/view/admin/includes/header.php');
    include('application/view/admin/news/update.php');
    include('application/view/admin/includes/footer.php');
}

In my view a have a form that displays the attributes such as <?php echo $model->title; ?>

In my database table, the fields publisher and image are not present, so I am getting an “undefined property: stdClass” error. However I need to keep these fields in the view for future use. How can I bring in the public model variables to be part of the model object whenever I make a call to the model? (in this case I want them to just return a null value)

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

    It’s not the perfect model class, but I think it comes close to yours while offering a more direct interface to it’s values:

    class News
    {
        public $title;
        public $article;
        public $date;
        public $published;
        public $publisher;
        public $image;
    
        public function getSingleArticleRow($id)
        {
            $query = "SELECT *, date_format(date, '%D %M %Y') AS uk_date FROM news WHERE id=$id";
            return mysql_query($query);
        }
    
        public function loadSingleArticle($id)
        {
            $obj = mysql_fetch_object($this->getSingleArticleRow($id));
            foreach($obj as $key => $value)
                $this->{$key} = $value;
        }
    }
    

    Controller:

    public function editAction()
    {
        $model = new News();
        $model->loadSingleArticle($_GET['id']);
    
        include('application/view/admin/includes/header.php');
        include('application/view/admin/news/update.php');
        include('application/view/admin/includes/footer.php');
    }
    

    However you should really look into PDO because it allows to fetch objects from the database more specifically and more streamlined.

    Also use parametrized queries because of the SQL injection that is available as a build-in feature to extend the SQL on the fly via the $id parameter. I assume you don’t want that.

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

Sidebar

Related Questions

I've simple Django model of news entry: class NewsEntry(models.Model): pub_date = models.DateTimeField('date published') title
This is my model: class News(models.Model): title = models.CharField(max_length=250) text = models.TextField() pub_date =
Imagine, I have News models with many text fields class News(models.Model): title = models.CharField(max_length=255)
I have these models: class Gallery(models.Model): HeadImage = models.ImageField(upload_to=gallery,blank=True,null=True) class News(Gallery): Name=models.CharField(max_length=100) #some other
My Model Class as follows: public class Employee { public Guid ID { get;
I have a simple model with news and categories: class Category(models.Model): name = models.CharField()
Here is my model: public class NewsCategoriesModel { public int NewsCategoriesID { get; set;
I have few similar models in Django: class Material(models.Model): title = models.CharField(max_length=255) class Meta:
so heres the deal i have Models public class News { public News() {
I have two classes public class News { public virtual int Id { get;

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.