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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:11:49+00:00 2026-05-31T15:11:49+00:00

Ok, I need a little help. I have these two PHP classes class menu

  • 0

Ok, I need a little help. I have these two PHP classes

class menu
{
    public static function GetItems ()
    {
        $res=array();
        $r=mysql_query("select * from menuitems");
        while($rw=mysql_fetch_row($r))
        $res[]=new MenuItem($rw[0],$rw[1],$rw[2],$rw[3]);
        return $res;
    }
}

And second

class Articles
{
    public static function Get ()
    {
        $res=array();
        $r=mysql_query("select * from articles");
        while($rw=mysql_fetch_row($r))
            $res[]=new Articles($rw[0],$rw[1],$rw[2],$rw[3]);
        return $res;
    }
}

I need a simple PHP interface class that can write all this inside, just to change MENUITEMS, and articles. Basically I need something like this as an interface

interface Base
{
    $res=array();
    $r=mysql_query("select * from $base");
    while($rw=mysql_fetch_row($r))
        $res[]=new $base($rw[0],$rw[1],$rw[2],$rw[3]);
    return $res;
}
}

And in the other class I need something that I can calllike this

 class menu
 {
    public static function GetItems ()
    {
        $baza="Articles";
    }
}

You know what I mean, my class Menu needs to implements class baza, and there was $baza, just replace with this string?

Ok, lots of says can not do that in interface, i agree, but i need solution, for my question?

  • 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-31T15:11:51+00:00Added an answer on May 31, 2026 at 3:11 pm

    You’re looking for inheritance, rather than “interface.” An interface says that an object that implements it will have certain methods, but must provide the body for them. In your case, you’ll probably do best with an abstract class that has a concrete method of, we’ll say, Get() and then an abstract method of GetTable().

    abstract class DatabaseObject {
    
        abstract protected function GetTable();
    
        public function Get() {
            $res=array();
            $r=mysql_query("select * from " . $this->GetTable());
            while($rw=mysql_fetch_row($r))
                $res[]=new $base($rw[0],$rw[1],$rw[2],$rw[3]);
            return $res;
        }
    }
    

    Then you can extend that with your classes. For example:

    class menu extends DatabaseObject
    {
        protected function GetTable ()
        {
            return 'menuitems';
        }
    }
    

    And now you can use Get() on that object to get the items out of the table.

    The drawback with doing it this way is that you won’t be able to use a static method — you’ll have to create an instance of your class.

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

Sidebar

Related Questions

I have started to study UML standard and would need little help with two
Need a little help with a SQL / ActiveRecord query. Let's say I have
I need a little help on this subject. I have a Web application written
I have little snippet for validatin' my form. I need help to position the
I ran into a little problem and need some help: If I have an
I need little bit help related to android tabhost. I have 3 tabs and
need a little help with the regexp i make... have some text where links
I need a little help with some regex I have. Basically I have a
I need a little help, I have a report that I am running that
I need a little help getting a tar file to download from a website.

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.