我尝试选择跟随我的任何网站成员的用户数量,但即使数据库中没有空,它也会一直返回0,或者当它为空时显示为1
<?php
$db_conn = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME,DB_USERNAME,DB_PASSWORD);
$db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$followings = $db_conn->prepare("SELECT COUNT(*) FROM memberfollow WHERE following = :followMe");
$followings->bindParam(":followMe", $_POST['username']);
$followings->execute();
$Numfollowing = $followings->rowCount();//this will return 0 when is empty and not empty
$col = $followings->fetchColumn();// this will return 1 in all
echo "FL".$Numfollowing."/".$col."<br/>";
?>
答案 0 :(得分:0)
你可以写
<?php
$db_conn = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME,DB_USERNAME,DB_PASSWORD);
$db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$followings = $db_conn->prepare("SELECT * FROM memberfollow WHERE following = :followMe");
$followings->bindParam(":followMe", $_POST['username']);
$followings->execute();
$Numfollowing = $followings->rowCount();//this will return 0 when is empty and not empty
$col = $followings->fetchColumn();// this will return 1 in all
echo "FL".$Numfollowing."/".$col."<br/>";
?>
这可能会解决您的问题