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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:39:39+00:00 2026-05-11T19:39:39+00:00

EDIT: I got this working now. I have updated the code: I’ve looked at

  • 0

EDIT: I got this working now. I have updated the code:

I’ve looked at a few examples in here, and they all look logical. But I can’t get it to work. I have a class that extends my Data Access Layer (DAL). I would like to call parent class to retrieve DB results. What am I doig wrong?

DAL class

class DAL { 
  protected $username;     // the username for db connect 
  protected $pwd;          // the pwd to use when connecting 
  protected $host;         // the host to which one connects 
  protected $dbname;       // the db to select 
  public $conn;          // reference to the db link resource 
  public $db;            // result of db_select 
  public $query_result;  // the stored result of the last query you ran 

  public function __construct() 
  { 
    $this->username     = ""; 
    $this->pwd          = ""; 
    $this->host         = ""; 
    $this->dbname       = ""; 
  } 

  public function connect() 
  { 
    /* connects to DB here */
  }  

  private function query($sql) 
  {
    /* Executes the query here and stores the result in $this->query_result */
  }

  public function getAllCountries()
  {
    $sql =" 
      SELECT id, name
      FROM country";

    //Process query
    $this->query($sql);

    if($this->query_result)
      return $this->query_result;      
  }
}

And this is my other class

class myOtherClass extends DAL{

  public function __construct() {
   parent::__construct();
   parent::connect();
  }

  public function getCountryListBox()
  {
    $result = parent::getAllCountries();

    if($result)
    {
      $selectbox = "<select id='countryListBox' name='countryListBox'>";

      while ($row = mysql_fetch_array($result))
      {
        $selectbox .= "<option value='".($row['id'])."'>".($row['name'])."</option>";
      }
      $selectbox .= "</select>";
    }
    else
      $selectbox = "Countries could not be retrievd from database.";

    return  $selectbox;    
  }  
}

This is the code in my template:

$sl = new myOtherClass();

echo '<form id="label_data_form">';
  $sl->getCountryListBox(); 
echo '</form>';
  • 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-11T19:39:39+00:00Added an answer on May 11, 2026 at 7:39 pm

    The difference between these:

    // $result = parent::getAllCountries();  // Like this
    $result = this->getAllCountries();       // Or like this?
    

    .. is probably best explained here:

    class SuperFoo {
        function fubar () {
            echo "superfoo!";
        }
    
        function fuz () {
            echo "superfuz!";
        }
    }
    
    class SubBar extends SuperFoo {
        function fubar() {
            echo "subbar!";
        }
    
        function demonstrate() {
            $this->fubar();    // "subbar!"
            parent::fubar();   // "superfoo!"
    
            $this->fuz();      // "superfuz!"
            parent::fuz();     // "superfuz!"
        }
    }
    
    $s = new SubBar();
    $s->demonstrate();
    

    (okay, maybe not best explained..)

    Unless you particularly want the behaviour defined in the parent class, I’d always use $this->... since then you have the option of altering the behaviour if needed.


    The MySQL error seems to be caused by a problem with your SQL – the class inheritance looks to be working fine.

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

Sidebar

Related Questions

This is what I got so far, and it's not working at all :(
EDIT: I got it working it just won't download anything... So here is my
I've got a form where users can edit members of a group. So they
I've got a treeview control, and have caught its after-label-edit event. I want to
I have got this project that uses excel for some calculation. This excel is
I have looked around SO and the web for quite some time now and
I had this working to spec, until the specs changed. This function is now
EDIT: This got way too complicated, I will migrate this question to another question
Edit : I've got an aspx file (default.aspx) that loads a flash file (index.swf),
I've got to edit an XSLT stylesheet, but I'm flying blind because the XML

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.