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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:25:17+00:00 2026-05-26T03:25:17+00:00

The class below is my first attempt at writing my own OOP application. I’ve

  • 0

The class below is my first attempt at writing my own OOP application. I’ve used procedural for a while and the OO techniques are not coming as easily as I’d hoped.

The class is designed to put together input elements for HTML forms, optionally using SQL table records. I’m starting with the select box and will add more when I get this much working.

So the problem is that I’m getting

“Call to a member function get_table() on a non-object” on the ‘public function get_table()’ line of the Class code below.

I’m not sure why this is happening. Help/tips would be GREATLY appreciated.

and now the code:

Application:

        $_input = new html_form_input();
        $_input->set_input_type('select');
        $_input->set_table('stores');
        $_input->set_fieldname_id('store_id');
        $_input->set_fieldname_desc('store_name');
        $_input->set_sql_order(' ORDER BY store_name ASC ');
        $_input->set_select();

        $html_select_facility =  $_input->get_select();

Class:

class html_form_input 
{

    public $input_type;
    public $table;
    public $fieldname_id;
    public $fieldname_desc;
    public $passed_id;
    public $sql_where;
    public $sql_order;
    public $array_input_options;


    public function __construct()
    {
        // constructor method
    }

    /*
        setters
    */
    public function set_input_type($input_type)
    {
        $this->input_type = $input_type;
    }
    public function set_array_input_options($array_input_options)
    {
        $this->array_input_options = $array_input_options;
    }
    public function set_table($table)
    {
        $this->table = $table;
    }
    public function set_fieldname_id($fieldname_id)
    {
        $this->fieldname_id = $fieldname_id;
    }
    public function set_fieldname_desc($fieldname_desc)
    {
        $this->fieldname_desc = $fieldname_desc;
    }
    public function set_passed_id($passed_id)
    {
        $this->passed_id = $passed_id;
    }
    public function set_sql_where($sql_where)
    {
        $this->sql_where = $sql_where;
    }
    public function set_sql_order($sql_order)
    {
        $this->sql_order = $sql_order;
    }


    /*
        getters
    */
    public function get_input_type()
    {
        return $this->$input_type;
    }
    public function get_array_input_options()
    {
        return $this->$array_input_options;
    }
    public function get_table()
    {
        return $this->$table;
    }
    public function get_fieldname_id()
    {
        return $this->$fieldname_id;
    }
    public function get_fieldname_desc()
    {
        return $this->$fieldname_desc;
    }
    public function get_passed_id()
    {
        return $this->$passed_id;
    }
    public function get_sql_where()
    {
        return $this->$sql_where;
    }
    public function get_sql_order()
    {
        return $this->$sql_order;
    }




    /*
        set_query_form_data() queries the database for records to be used in the input element. 
    */
    public function set_query_form_data()
    {

        global $dbx;

        $debug = true;
        $_debug_desc        = "<span style='color:blue;'>function</span> <b>set_query_form_data</b>()";
        if ($debug)         { echo "<p>BEGIN $_debug_desc <blockquote>"; }

        $table->get_table();
        $fieldname_id->get_fieldname_id();
        $fieldname_desc->get_fieldname_desc();
        $passed_id->get_passed_id();
        $sql_where->get_sql_where();
        $sql_order->get_sql_order();

        if ($passed_id)
        {
            if (!is_array($passed_id))
            {
                $passed_id[] = $passed_id;
            }
        }

        if ($sql_where!='')
        {
            $sql_where = " WHERE $sql_where ";
        }


        $q = "
            SELECT
                $fieldname_id,
                $fieldname_desc 
            FROM 
                $table 
            $sql_where
            $sql_order
        ";
        $res = $mdb2_dbx->query($q);
        if (PEAR::isError($res)) {  gor_error_handler($res, $q, __LINE__,__FILE__,'die'); }
        while ( $r = $res->fetchRow(MDB2_FETCHMODE_ASSOC) )
        {
            $id     = $r[$fieldname_id];
            $desc   = $r[$fieldname_desc];
            $array_values[$id] = $desc;
        }

        $this->sql_array_values = $array_values;

        if ($debug) { echo "<p></blockquote>END $_debug_desc ";  }
    }

    /*
        getter for set_query_form_data (above)
    */
    public function get_query_form_data()
    {
        return $this->$array_values;
    }


    /*
        set_select() pieces together a select input element using database derived records, or a passed array of values. 
    */
    public function set_select($flag_query_db=1, $array_static_values=null)
    {

        if ($flag_query_db==1)
        {

            $array_values = $this->set_query_form_data();

        } else if (is_array($array_static_values)) {

            $array_values = $array_static_values;

        }


        $array_values   = $array_data['row_data'];
        $fieldname_id   = $array_data['fieldname_id'];
        $fieldname_desc = $array_data['fieldname_desc'];
        $passed_id      = $array_data['passed_id'];

        if (!is_array($passed_id))
        {
            $passed_id[] = $passed_id;
        }


        foreach ($array_values as $id=>$desc)
        {

            // handle passed values (multiple or single)
            $sel = null;
            if (in_array($id,$passed_id))
            {
                $sel = ' selected ';
            }

            // construct html
            $html_options .= " <option value='$id' $sel>$desc</option>\n";

        }

        $disabled   = null;
        $multiple   = null;
        $size       = null;
        $style      = null;
        $class      = null;
        $element_id = null;
        $javascript = null;

        if (is_array($array_input_options))
        {
            $s_disabled     = $array_input_options['disabled'];
            $s_multiple     = $array_input_options['multiple'];
            $s_size         = $array_input_options['size'];
            $s_style        = $array_input_options['style'];
            $s_id           = $array_input_options['id'];
            $s_class        = $array_input_options['class'];
            $s_javascript   = $array_input_options['javascript'];

            if ($s_disabled!='')    {$disabled      = ' disabled '; }
            if ($s_multiple!='')    {$multiple      = ' multiple '; }
            if ($s_size!='')        {$size          = ' size="'     . $s_size . '"'; }
            if ($s_style!='')       {$style         = ' style = "'  . $s_style . '"'; }
            if ($s_id!='')          {$element_id    = ' id = "'     . $s_id . '"'; }
            if ($s_class!='')       {$class         = ' class = "'  . $s_class . '"'; }
            if ($s_javascript!='')  {$javascript    = $s_javascript; }
        }

        $html = "
            <select name='$fieldname_id' $element_id $disabled $multiple $size $style $class $javascript>
                $html_options
            </select>
        ";

        $this->select_html = $html;

    }


    /*
        getter for set_select (above)
    */
    public function get_select()
    {
        return $this->$select_html;
    }


}
  • 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-26T03:25:18+00:00Added an answer on May 26, 2026 at 3:25 am

    In the following code, $table hasn’t been initialised.

    public function set_query_form_data()
    {
    
        global $dbx;
    
        $debug = true;
        $_debug_desc        = "<span style='color:blue;'>function</span> <b>set_query_form_data</b>()";
        if ($debug)         { echo "<p>BEGIN $_debug_desc <blockquote>"; }
    
        $table->get_table();
    

    You probably intend it to be $this, i.e. “the object currently being used”:

    public function set_query_form_data()
    {
    
        global $dbx;
    
        $debug = true;
        $_debug_desc        = "<span style='color:blue;'>function</span> <b>set_query_form_data</b>()";
        if ($debug)         { echo "<p>BEGIN $_debug_desc <blockquote>"; }
    
        $this->get_table();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing my first C# web application that connects to an XML based service.
This is my first website attempt and I've been following a great tutorial while
Below is a first attempt at using a Composite pattern. It works in the
I'm writing an application that catalog files and saves meta data with them through
Please see my first attempt at answering this . I neglected to tell the
I have a simple class as defined below: public class Person { int _id;
I have a standalone Java application below that is: Generating a random line Applied
I create a form based on a model , like seen below: class ContactSelectionForm(forms.ModelForm):
I want to implement FSM like below First Level Most basic State is BASE_STATE.
i have a class like below public class Foo<T> { public List<T> Items{ 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.