0

is there any way to access the variables of this function outside ?

            public function selectData($table, $where = null, $wheree = null, $where1 = null, $wheree1 = null) {
                    $QUERY = mysql_query("SELECT * FROM " . $table . " WHERE '" . $where . "' = '" . $wheree . "' && '" . $where1 . "' = '" . $wheree1 . "'");
                    $Fetch_Assoc = mysql_fetch_assoc($QUERY);
                    $Num_Rows = mysql_num_rows($QUERY);
                    $Fetch_Array = mysql_fetch_array($QUERY);
                    $Fetch_Object = mysql_fetch_object($QUERY);

            }

I need it please !!

2
Contributors
1
Reply
19
Views
2 Years
Discussion Span
Last Post by broj1
0

Please post the whole class structure not only one method.

$Fetch_Assoc, $Fetch_Array, $Num_Rows and $Fetch_Object should be either assigned to some properties or somehow returned by the function. There is a third option which is that these variables were made global but that would defeat the purpose of OOP.

An example (made up, do not copy it):

class $DB_handler
{
    protected $Fetch_Assoc = array();
    protected $Fetch_Array = array();
    protected $Fetch_Object = null;
    protected $Num_Rows = null;

    protected function selectData($table, $where = null, $wheree = null, $where1 = null, $wheree1 = null) 
    {
        $QUERY = mysql_query("SELECT * FROM " . $table . " WHERE '" . $where . "' = '" . $wheree . "' && '" . $where1 . "' = '" . $wheree1 . "'");
        $this->Fetch_Assoc = mysql_fetch_assoc($QUERY);
        $this->Num_Rows = mysql_num_rows($QUERY);
        $this->Fetch_Array = mysql_fetch_array($QUERY);
        $this->Fetch_Object = mysql_fetch_object($QUERY);

    }

    public function getArray
    {
        return $this->Fetch_Assoc;
    }

    public function getAssoc
    {
        return $this->Fetch_Array;
    }
    ...
}

// initialize class
$obj = new $DB_handler;
$obj->SelectData('table_name');
$temp = $obj->getAssoc();
echo $temp['P_id'];

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.