displaying 'first letter' html tags to a MySQL query result
<p>After much tinkering, I have managed to get my code to work where the results are grouped together by the first letter with that first letter being displayed also as shown below:</p>

<pre><code>-A-
Alton Towers

-C-
Cedar Point
Chessington
</code></pre>

<p>etc.</p>

<p>I have turned those letter headings into HTML anchors. What I'm trying to do now is run similar code that just displays the first letters in a line at the top of page which are links to each anchor. I can't get the code to work. If I duplicate the code and modify it just to show letters, the original query list doesn't display. Can someone help? Below is the code used to display the query results with the letter headings.</p>

<pre><code>try
{
$sql = 'SELECT park_id, name, town, state, country
FROM tpf_parks ORDER BY name ASC';
$result = $pdo-&gt;query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching parks: ' . $e-&gt;getMessage();
//include 'error.html.php';//
exit();
}


$name = '';


foreach($result as $key=&gt;$row){
    if(substr($row['name'],0,1)!=$name) echo '&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;-&lt;a name="'.substr($row['name'],0,1).'"&gt;'.substr($row

['name'],0,1).'-&lt;/h1&gt;&lt;/a&gt;';
    $name = substr($row['name'],0,1);

    echo "&lt;a href='park.php?park_id=".$row['park_id']."'&gt;

&lt;h2&gt;".$row['name']."&lt;/h2&gt;
&lt;h3&gt;".$row['town'].", ".$row['state'].", ".$row['country']."&lt;/h3&gt;&lt;/a&gt;&lt;hr&gt;";


}
</code></pre>
