[Solved] how to fetch data from a database?


Try with below code, it should work.

    $output = array();
$output2 = '';
foreach($this->CoachPlayers as $key => $value){
    $coachName = $value['coachName'];
    $coachImage = $value['icon'];
    if (!array_key_exists($coachName, $output)) {
        $output[$coachName] = array();
    }
    $player = array();
    $player['name'] = $value['name'];
    $player['age'] = $value['age'];
    $output[$coachName][] = $player;
    $output[$coachName]['image'] = $value['icon'];
}

foreach($output as $data => $values) {
    $coachImage = $values['image'];
    echo  "<h1>".$data."</h1>";
    echo '<div style="text-align:center;"><img src="'.URL."public/images/coaches/".$coachImage.'"/></div>';

    if(is_array($values)) {
        foreach ($values as $key => $player) {
            echo '<p>'.$player['name'].'</p>';
            echo '<p>'.$player['age'].'</p>';
        }
    }
}

solved how to fetch data from a database?