我想檢查名稱是否存在。查詢應返回0,因爲該字段爲空,但返回1。幫幫我。PHP的MySQL COUNT不返回而不是0
function profile_exists($user) { //checks that profile exists
$profile_ex = mysql_query(
"SELECT COUNT(profile_name) FROM user_info WHERE id = '{$user}'");
if(!confirm_query($profile_ex)) {
return false;
} else {
if (mysql_result($profile_ex, 0) == 1) {
echo mysql_result($profile_ex, 0);
exit;
return true;
} else {
return false;
}
}
}
[**在新代碼請不要使用'mysql_ *'功能**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit 2013-02-15 21:45:14