如何删除重复的Json信息?

DNu*_*DNu 9 php mysql arrays jquery json

数据库:

`--> product table
id  name      cid     uploadKey
1   Cemera     1       7365
2   Notebook   2       7222`

`--> category table
id    catename
1      canon
2      toshiba`


`--> attactments table
id      uploadKey       filepath
1       7365            /img/jdf.png
2       7365            /img/sdsd.jpg`
Run Code Online (Sandbox Code Playgroud)

这段代码创建json文件:

$_GET['id']="1";
 $json_response = array();
    if(isset($_GET['id']))
    {
        $id=$_GET['id'];        
 $select = mysql_query("SELECT product.name,category.catename,attactments.filepath FROM product INNER JOIN category ON category.id = product.cid INNER JOIN attactments ON attactments.uploadKey = product.uploadKey where product.id='".$id."'  ");
    while ($row = mysql_fetch_array($select , MYSQL_ASSOC)) {       
        $json_response[] = $row;
         } 
    }
 echo $val= str_replace('\\/', '/', json_encode($json_response));
Run Code Online (Sandbox Code Playgroud)

结果重复信息,如何删除重复我想显示如下:

[{"name":"Cemera","catename":"canon","filepath":"/img/jdf.png"},{"name":"Cemera","catename":"canon","filepath":"/img/sdsd.jpg"}]
Run Code Online (Sandbox Code Playgroud)

我想像这样展示我们如何编辑它:

[{"name":"Cemera","catename":"canon","filepath":"/img/jdf.png","filepath":"/img/sdsd.jpg"}]
Run Code Online (Sandbox Code Playgroud)

KTA*_*Anj 2

您可以GROUP_CONCAT() 文件路径,尝试以下代码

$select = mysql_query("SELECT product.name,category.catename,GROUP_CONCAT(attactments.filepath SEPARATOR ',') AS filepath FROM product INNER JOIN category ON category.id = product.cid INNER JOIN attactments ON attactments.uploadKey = product.uploadKey where product.id='".$id."'  ");

while ($row = mysql_fetch_array($select , MYSQL_ASSOC)) {   
   $row['filepath'] = explode(',',$row['filepath']);
        $json_response[] = $row;
         } 
Run Code Online (Sandbox Code Playgroud)

然后你会得到以下结果

{"name":"Cemera","catename":"canon","filepath":["\/img\/jdf.png","\/img\/sdsd.jpg"]}
Run Code Online (Sandbox Code Playgroud)