当我定义了一个函数时,我收到call to undefined function
错误。这是代码:
foreach($db->query("SELECT * FROM 'members' WHERE username = '$user'") as $row) {
echo "Rank: ".get_rank_tag($user)."<br>";
}
以下是get_rank_tag()
功能
include('password.php');
class User extends Password {
private $_db;
function __construct($db) {
parent::__construct();
$this->_db = $db;
}
public function get_rank_tag($user){
try {
$stmt = $this->_db->prepare('SELECT rank FROM members WHERE username = $user ');
$stmt->execute();
$row = $stmt->fetch();
if($row['rank']==0){return "<span class='label label-default'>Default</span>";}
elseif($row['rank']==1){return "<span class='label label-success'>VIP</span>";}
elseif($row['rank']==2){return "<span class='label label-success'>MVP</span>";}
elseif($row['rank']==3){return "<span class='label label-success'>Elite</span>";}
elseif($row['rank']==4){return "<span class='label label-success'>Master</span>";}
elseif($row['rank']==5){return "<span class='label label-success'>Champion</span>";}
elseif($row['rank']==6){return "<span class='label label-primary'>JM</span>";}
elseif($row['rank']==7){return "<span class='label label-primary'>Trusted</span>";}
elseif($row['rank']==8){return "<span class='label label-info'>GM</span>";}
elseif($row['rank']==9){return "<span class='label label-info'>GM+</span>";}
elseif($row['rank']==10){return "<span class='label label-warning'>Admin</span>";}
elseif($row['rank']==11){return "<span class='label label-danger'>Owner</span>";}
} catch(PDOException $e) {
echo '';
}
}
}
我是PHP的初学者,所以请耐心等待。
答案 0 :(得分:0)
您确定您拥有User
课程的实例吗?确保你已经实例化了这个类,因为PHP无法识别你的函数。
答案 1 :(得分:0)
你必须先创建一个新的类实例才能开始调用它中的函数,否则它不知道在哪里查找函数
$newUser = new User($db);
$dataHold = $newUser->get_rank_tag($user);
然后你可以使用$dataHold
来回应你的排名。