本文介紹了mysqli_num_rows 返回 1 無論如何的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我在 phpMyAdmin 中進行 SQL 搜索(用變量代替實際值)時,它返回正確的行號,但是當使用 PHP 返回這個值時,無論如何它總是返回 1.提前致謝.
When I do a SQL search in phpMyAdmin (substituting the variable for the actual value) it returns the correct row number but when using PHP to return this value it always returns 1 no matter what. Thanks in advance.
function user_exists($username) {
$link = mysqli_connect('localhost','root','','test');
$username = sanitize($username);
$query = mysqli_query($link, "SELECT COUNT(`user_id`) FROM `new_base` WHERE `username`='$username'");
$row_cnt = mysqli_num_rows($query);
echo $row_cnt;
mysqli_free_result($query);
mysqli_close($link);
}
推薦答案
當你使用 COUNT(*)
你即使計數為零也總是返回一行.
你要么:
- 想去掉
count(*)
然后使用mysqli_num_rows()
或 - 獲取
count(*)
的結果
- Want to remove the
count(*)
and then usemysqli_num_rows()
or - Get the result of
count(*)
.
$row = mysqli_fetch_assoc($query);
echo $row['COUNT(`user_id`)'];
這篇關于mysqli_num_rows 返回 1 無論如何的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!