Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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 如何使数组的输出与众不同?_Php_Html_Postgresql - Fatal编程技术网

Php 如何使数组的输出与众不同?

Php 如何使数组的输出与众不同?,php,html,postgresql,Php,Html,Postgresql,我能够解决这个问题,但是,当我回显我的客户id时,有很多重复,我尝试将数组设置为唯一和不同的,但没有任何效果,我还能做什么?我还希望它显示所有地址,因为有些客户机有多个地址 $query1= "Select distinct client_id from client_profile where client_status= 'f'"; $result1= pg_query($conn2, $query1); $clientid = array(); whi

我能够解决这个问题,但是,当我回显我的客户id时,有很多重复,我尝试将数组设置为唯一和不同的,但没有任何效果,我还能做什么?我还希望它显示所有地址,因为有些客户机有多个地址

 $query1= "Select distinct client_id from client_profile where client_status= 'f'";

        $result1= pg_query($conn2, $query1);

    $clientid = array();
    while($row1 = pg_fetch_array($result1)){
        $id=$row1['client_id'];
        $clientid[]=$id;
        $clientid = array_unique($clientid);

    }

    //$clientid=array_unique($clientid);
    $clientid=implode(',',$clientid);


    $query= "select * from vouchers where client_id IN ($clientid)";

    $result = pg_query($conn,$query);



    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title>Inactive Clients</title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <link href = "http://fonts.googleapis.com/css?family=Roboto:400">
    </head>
        <body>  
    <table class="table table-sm">
      <thead>
        <tr>
          <th>Client id</th>
          <th>File Name</th>
        </tr>
      </thead>
      <?php 

        while($row = pg_fetch_array($result))
        { 


      ?>

      <tbody>

        <tr>
          <td><?php echo $row['client_id']; ?></td>
          <td><?php echo $row['file_name']; ?></td>


        </tr>
      <?php  }?>  </tbody>
    </table>
    </body> 
    </html>
$query1=“从客户端配置文件中选择不同的客户端id,其中客户端状态='f';
$result1=pg_查询($conn2,$query1);
$clientid=array();
而($row1=pg_fetch_数组($result1)){
$id=$row1['client_id'];
$clientid[]=$id;
$clientid=array\u unique($clientid);
}
//$clientid=array\u unique($clientid);
$clientid=内爆(“,”,$clientid);
$query=“从客户id为($clientid)”的凭证中选择*;
$result=pg_查询($conn,$query);
?>
非活动客户端
客户端id
文件名

您可以使用
GROUP BY
子句。在这种情况下,您的查询可以如下所示:

查询1

<?php    
    $query1  = "SELECT client_id FROM `client_profile` AS CP ";
    $query1 .= " WHERE CP.client_status='f' GROUP BY CP.client_id ";

尝试运行以下查询。还要检查列名是否正确

select client_id,array_agg(address_Field_column) from vouchers where client_id IN (select distinct client_id from client_profile where client_status= 'f') group by client_id;
我不知道您使用的是哪个PostgreSQL版本。 在mysql中,有一个group\u concat函数。
作为参考

在查询的开头输入“选择不同”
您可能需要将其放置多次。

重复发生在哪个查询上?我认为这是第二个查询,您可以检查凭证,而不是第一个。第一个应该很好。您还应该在希望值唯一的表上使用UNIQUE(在您的情况下,client_id在client_profile中应该是唯一的,那么您就不需要在那里使用DISTINCT)。
select client_id,array_agg(address_Field_column) from vouchers where client_id IN (select distinct client_id from client_profile where client_status= 'f') group by client_id;