Jump to content

Archived

This topic is now archived and is closed to further replies.

wackyflik

How to pass value from parent class to child class.

Recommended Posts

[code]class Users
{
    var $u_id;
    
    function Users()
    {
        // nothing
    }        
    
    function addUsers($u_id, $u_name, $u_icno, $u_gender, $u_race, $u_design, $u_address, $u_phoneno, $u_usrname, $u_pwd)
    {
        global $ecisDB;    
        
        $this->u_id = $u_id;
            
        $sql = "INSERT INTO users (usersId, usersName, usersIcNo, usersGender, usersRace, usersDesignation, usersAddress, usersPhoneNo, usersUsername, usersPassword)
               VALUE ('$u_id', '$u_name', '$u_icno', '$u_gender', '$u_race', '$u_design', '$u_address', '$u_phoneno', '$u_usrname', '$u_pwd')";
        $query = $ecisDB->query($sql) or die(mysql_error());
        
        //pass user id to child classes: 1. clerk 2.doctor 3. nurse
        return $u_id;
    }
    
    function loadDesignation()
    {
        $designation = array("Clerk", "Doctor", "Nurse");
        return $designation;
    }
    
    function loadGender()
    {
        $gender = array("Female", "Male");
        return $gender;
    }
    
    function loadRace()
    {
        $race = array("Chinese", "Indian", "Malay", "Others");
        return $race;
    }
    
    function checkString($string)
    {
        $pattern = "/^[a-zA-Z\.\ ]+$/";
        //$pattern = "/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\.\ ]+$/";
        if(preg_match($pattern, $string))
            return true;
        else
            return false;
    }
    
    function checkIcNo($u_icno)
    {
        if(is_numeric($$u_icno)){
            if(!strlen($$u_icno)==12)
                return true;
            else
                return false;
        }
        else
            return false;
    }
    
    function checkUName($u_usrname)
    {
        global $ecisDB;        
        $sql = "SELECT * FROM users WHERE usersUsername=\"$u_usrname\"";
        $query = $ecisDB->query($sql); //$result
        $count = $ecisDB->sql_count($query); //$result
        
        if ($count == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function checkPwd($u_pwd, $u_repwd)
    {
        if($u_pwd == $u_repwd)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function usersLogin($u_usrname, $u_pwd)
    {
        global $ecisDB;
        session_start();        
        $sql = "SELECT * FROM Users WHERE usersUsername = \"" . $u_usrname . "\" AND usersPassword = \"" . $u_pwd . "\"";
        $query = $ecisDB->query($sql);
        $count = $ecisDB->sql_count($query);
        $row = $ecisDB->fetch_array($query);  //$query
        
        if ($count != 0)
        {
            $_SESSION['u_id'] = $row['usersId'];
            $_SESSION['u_name'] = $row['usersName'];
            //$_SESSION['level'] = $row['usersDesignation'];
            header("Location: ../index.php");
        }
        else{
            header("Location: ../index.php");
        }
    }
    
    function usersLogout($goto="")
    {
        session_start();
        $_SESSION['u_id'] = '';
        $_SESSION['u_name'] = '';
        if(!empty($goto)){
            header("Location: ../" . $goto);
        }
    }
    
    function &getUserInfo($u_id)
    {
        global $ecisDB;
        $sql = "SELECT * FROM Users WHERE usersId = " . $u_id;
        $query = $ecisDB->query($sql) or die (mysql_error());
        $row = $ecisDB->fetch_array($query);
        return $row;
    }
    
    function updateUsers($u_id, $u_name, $u_icno, $u_gender, $u_race, $u_design, $u_address, $u_phoneno)
    {
        global $ecisDB;
        $sql = "UPDATE Users SET usersName = \"$u_name\",
                                 usersIcNo = \"$u_icno\",
                                 usersGender = \"$u_gender\",
                                 usersRace = \"$u_race\",
                                 usersDesignation = \"$u_design\",
                                 usersAddress = \"$u_address\",
                                 usersPhoneNo = \"$u_phoneno\"
                                 WHERE usersId = " . $u_id;
        $query = $ecisDB->query($sql);
    }
    
    function updatePassword($u_id, $new_pwd1)
    {
        global $ecisDB;
        $sql = "UPDATE Users SET usersPassword = \"$new_pwd1\" WHERE usersId = " . $u_id;
        $query = $ecisDB->query($sql);
    }
}

class Clerk extends Users
{
    function Clerk()
    {
        //nothing
    }
    
    function addClerk($u_id)
    {
        global $ecisDB;
        $clerkId = $this->addUsers($u_id, $u_name, $u_icno, $u_gender, $u_race, $u_design, $u_address, $u_phoneno, $u_usrname, $u_pwd);
        $sql = "INSERT INTO Clerk (clerkId) VALUE ('$u_id')";
        $query = $ecisDB->query($sql) or die(mysql_error());
    }
}
[/code]


there are 2 classes: Users is a parent class and Clerk is a child class. in parent class there is a function named addUsers with several arguments and 1 of it is user id (u_id). i want to pass the user id (u_id) from addUsers to addClerk. how to that? thank you.

Share this post


Link to post
Share on other sites
Answer may be here...

[a href=\"http://us2.php.net/keyword.parent\" target=\"_blank\"]http://us2.php.net/keyword.parent[/a]

Lite...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.