distinct 禁止重复,下面例子:
//查数据 $sql = "select distinct sex,name,email from user";//查询语句 注意from不要写错 $result = mysqli_query($link,$sql); //query()链接上数据库执行语句 if(mysqli_num_rows($result)>0){//是否查询的结果>0 while ($row = mysqli_fetch_assoc($result))//循环输出 { echo "邮箱:" .$row['name'] .","; echo "邮箱:" .$row['email'] .","; echo "姓名:" .($row['sex'] == '0' ? '女' : '男')."<hr>"; }; }else{ echo '错误'; }
结果是