Sql得到多个同一行[关闭]

$uid is 6

    public function getUserGroups($uid) {
    $sql = "SELECT groups.id, groups.name, groups.type , groups.img_path, DATE_FORMAT(user_group.joined_at,'%e/%c/%Y %H:%i') joined_at FROM groups JOIN user_group ON groups.id = user_group.group_id WHERE groups.id IN (SELECT group_id FROM user_group WHERE user_id = ?)";
    $query = $this->db->prepare($sql);
    $query->execute(array($uid));
    if($query->rowCount()) {
        $user_groups = $query->fetchAll();
        return $user_groups;
    }
    return false;
}

This function bring true data from tables but multiple times. Here the outputs :

array (size=2)
  0 => 
    array (size=10)
      'id' => string '4' (length=1)
      0 => string '4' (length=1)
      'name' => string 'Test Grubu' (length=10)
      1 => string 'Test Grubu' (length=10)
      'type' => string 'Açık Grup' (length=11)
      2 => string 'Açık Grup' (length=11)
      'img_path' => string 'images/groupimages/11-09-2015-12-48-56_ic_participation_off.png' (length=63)
      3 => string 'images/groupimages/11-09-2015-12-48-56_ic_participation_off.png' (length=63)
      'joined_at' => string '9/11/2015 00:48' (length=15)
      4 => string '9/11/2015 00:48' (length=15)
  1 => 
    array (size=10)
      'id' => string '4' (length=1)
      0 => string '4' (length=1)
      'name' => string 'Test Grubu' (length=10)
      1 => string 'Test Grubu' (length=10)
      'type' => string 'Açık Grup' (length=11)
      2 => string 'Açık Grup' (length=11)
      'img_path' => string 'images/groupimages/11-09-2015-12-48-56_ic_participation_off.png' (length=63)
      3 => string 'images/groupimages/11-09-2015-12-48-56_ic_participation_off.png' (length=63)
      'joined_at' => string '9/11/2015 11:50' (length=15)
      4 => string '9/11/2015 11:50' (length=15)

user_group :

Group

groups :

enter image description here

I want to get user' s all group. I save to user_group, and all groups keeping in groups.

If I true understand your question, I think something like that:

SELECT
  groups.id,
  groups.name,
  groups.type,
  groups.img_path,
  DATE_FORMAT(user_group.joined_at, '%e/%c/%Y %H:%i') joined_at
FROM groups
  JOIN user_group ON groups.id = user_group.group_id
WHERE groups.id IN (SELECT group_id
                    FROM user_group
                    WHERE user_id = ?)
GROUP BY groups.id;