如何使用php文件获取数据库特定返回结果?

img


如上图所示,简单用excel做了一个类似数据库表,表名user,第一行为字段名称,现在的需求就是用php文件获取几个特定数据,1.获取男生有多少,2.女生有多少,3.有图片的有多少(这个不分男女,但是空值不能计算在内),有没有可能帮忙给个完整版的demo啊,真的抓耳挠腮,试了好多都是不尽如意。

比较简单的mysql语句

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 

function getdata($where,$conn){
    $sql="SELECT COUNT(*) FROM user where  $where ";
    $result= mysqli_query($conn, $sql);
    $rs=mysqli_fetch_array($result);
    echo $rs[0]."<br>";
}

getdata("sex='男'",$conn);
getdata("sex='女'",$conn);
getdata("name !=''",$conn);