當我定義函數時,出現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的,所以請大家多多包涵。
在哪裏調用未定義函數? – Chitowns24
...以及未定義函數的名稱是什麼?始終顯示完整的錯誤消息! –
@ Chitowns24當我說'「.get_rank_tag($ user)。」' – ryr11