Count Distinct Rows From MYSQL Table

Count Distinct Rows From MYSQL Table

Method A

$command= "SELECT count(distinct username) as allusername from tablename ";
$result = mysqli_query($db, $command);
if ($result && mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$myusername = $row['allusername'];
}
}

echo "The distinct count of usernames is ".$myusername."<br/>";

Method B

$command= "SELECT distinct username from tablename ORDER BY date asc ";
$result = mysqli_query($db, $command);
if ($result && mysqli_num_rows($result) > 0) {
$myusernames= mysqli_num_rows($result);
echo "The distinct count of usernames is ".$myusernames."<br/>";
}