Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在从我的sql DB提取时跳过重复值_Php_Mysql - Fatal编程技术网

Php 如何在从我的sql DB提取时跳过重复值

Php 如何在从我的sql DB提取时跳过重复值,php,mysql,Php,Mysql,我有一个问题。我正在从MYSQL表中获取一些数据。但是有一些重复的数据。我需要跳过那些重复的数据。我在下面解释我的代码 session_start(); $postdata = file_get_contents("php://input"); $request = json_decode($postdata); $colg_id=1; $dept_id = $_SESSION["admin_dept_id"]; $user_id=$_SESSION["admin_id"]; $connect

我有一个问题。我正在从MYSQL表中获取一些数据。但是有一些重复的数据。我需要跳过那些重复的数据。我在下面解释我的代码

session_start();
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$colg_id=1;
$dept_id = $_SESSION["admin_dept_id"];
$user_id=$_SESSION["admin_id"];
$connect = mysqli_connect("localhost", "root", "******", "go_fasto");
$result = mysqli_query($connect, "select plan_id,unit_name  from db_unit_plan where dept_id='".$dept_id."'  and user_id = '".$user_id."'   ");
while ($row =mysqli_fetch_assoc($result)) {
  $data[] = $row;
}
    print json_encode($data);

这里我需要知道,如果任何单位名称列具有相同的类型数据,那么如何跳过这些行。请帮助我。

使用DISTINCT这样更改

$result = mysqli_query($connect, "select DISTINCT unit_name,plan_id  from db_unit_plan where dept_id='".$dept_id."'  and user_id = '".$user_id."'   ");

您必须指定'DISTINCT'关键字才能从SQL中获得唯一的结果。 因此,只需尝试将select语句更改为
$result=mysqli\u query($connect,“select DISTINCT plan\u id..”)


祝你好运。

也许可以使用
选择不同的
?如rMX所说,检查选择计划id,不同的(单位名称)?不确定,但给它一个可能的复制品