Jump to content

How to pass value from parent class to child class.


wackyflik

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.