0

我让它像这个类一样工作:class useraccount{ private $username; 私人$姓氏;私人 $firstname;

    public function userProfileView ()
    {
            $varViewUser = mysql_query("SELECT * FROM users");
                $varusername = $_SESSION['username'];
                $varViewUserProfile = mysql_query("SELECT * FROM users WHERE username = '$varusername'");
                      while ($rows = mysql_fetch_array($varViewUserProfile)) {
                      $this->username = $rows['username'];
                      $this->firstname = $rows['user_firstname'];
                      $this->lastname = $rows['user_lastname'];
                      $this->email = $rows['email'];
                    }

            return $this->lastname;
            return $this->firstname;

    } 
  }

HTML:

名字:userProfileView(); ?>

现在我如何引用要显示的值?

4

1 回答 1

0

PHP 中的变量始终是函数的局部变量。

建议你重写

class useraccount{


  private $username;

  public function getUsername()
  {
    return $this->username;
  }

  public function userProfileView ()
  {
    while ($rows = mysql_fetch_array($varViewUser)) {
      $this->username  = $rows['username'];
        $Firstname = $rows['user_firstname'];
        $lastname = $rows['user_lastname'];
        $email = $rows['email'];
    }
  }


  include ('user_functions.php') ;$varuser = new useraccount; echo $varuser->getUsername();
于 2013-10-29T05:58:42.710 回答