I have this array coming form a DB PDO result, where users have made Hello there, I have this array coming form a DB PDO result, where users have made some feedback so it can be duplicated projects because a feedback can be either a comment or a suggestion
My DB Query
$this->sql = $this->dbh->query("SELECT idProject, title, excerpt
FROM projects AS up
JOIN comments AS co ON up.idProject = co.idProjectComment
WHERE co.idUserComment = $id");
$this->results = $this->sql->fetchAll(PDO::FETCH_ASSOC);
My Results
print_r($this->results);
Array
(
[0] => Array
(
[idProject] => 25
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
[1] => Array
(
[idProject] => 25
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
[2] => Array
(
[idProject] => 25
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
[3] => Array
(
[idProject] => 27
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
[4] => Array
(
[idProject] => 28
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
[5] => Array
(
[idProject] => 28
[title] => Lorem Ipsum
[excerpt] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...
)
)
As you can see, I got repeated projects, but I need to get rid of duplicated projects
Can anyone help me out to extract only one project and not duplicated items
I just want to get projects 25, 27 and 28
Thanks!!
Edited: Added Mysql tag + the for loop
$this->json['projects'] = array();
for($i=0; count($this->results) > $i; $i++){
$this->json['projects'][$i]['projectId'] = $this->results[$i]['idProject'];
$this->json['projects'][$i]['title'] = $this->results[$i]['title'];
$this->json['projects'][$i]['excerpt'] = $this->results[$i]['excerpt'];
}
return json_encode($this->json, JSON_PRETTY_PRINT);