This is my query:\[code\]try{ $sql = 'SELECT park_id, name, town, state, country FROM tpf_parks wHERE ORDER BY name ASC'; $result = $pdo->query($sql);}catch (PDOException $e){ $error = 'Error fetching parks: ' . $e->getMessage(); //include 'error.html.php';// exit();}$output = 'Parks Loaded';//include 'output.html.php';//foreach ($result as $row){ $parklist[] = array( 'park_id' => $row['park_id'], 'name' => $row['name'], 'town' => $row['town'], 'state' => $row['state'], 'country' => $row['country'] );}include 'parks.html.php';\[/code\]and this is parks.html.php\[code\]<?php foreach ($parklist as $park):?> <a href="http://stackoverflow.com/questions/15844966/park.php?park_id=<?php echo $park['park_id'];?>"> <h2><?php echo $park['name'];?></h2> <h3><?php echo $park['town'],',',$park['state'],',',$park['country'];?></h3> </a> <hr><?php endforeach; ?>\[/code\]I'm looking for some way that the foreach loop can be altered so I can split the results into groups sorted by the first letter. This is so I can put a html anchor for each Letter making it easier for the user to locate a particular record by clicking a link at the top of the page (A B C D E etc) . I am clueless as to how to achieve this.