咧:
一张名为user的表
id uid name pass
1   0    a    123
2   1    a    123
3   0    a    123
4   2    a    123
5   1    a    123
6   3    a    123
怎么获取uid为1的有几行?

解决方案 »

  1.   

    select count('id') from user where uid = 1
      

  2.   

    //数据库连接地址
    $host = "localhost";
    //数据库账号
    $dbname = "root";
    //数据库密码
    $dbpass = "123456";
    //操作的数据库
    $dbname = "test";
    //操作的数据表
    $dbtable = "table";
    //连接到mysql
    $conn = mysqli_connect($host,$username,$dbpass);
    if(mysqli_errno($conn)) {
    exut(mysqli_errno($conn));
    }
    //选择数据库
    mysqli_select_db($conn,$dbname);
    //查询的id
    $id = 1;
    //拼装查询语句
    $sql = "select * from $dbtable where uid = '$id'";
    //执行查询语句
    $result = mysqli_query($conn,$sql);
    //统计执行结果影响的行数
    $num = mysqli_num_rows($result);
    if($num) {
    echo "uid为{$id}的有{$num}行}<br/>";
    }//数据库配置信息需要修改成你自己机器配置的就行