Pulling state abbreviation from result and substituting full state name and use as heading
<p>I am trying to use PHP to retrieve the state abbreviation from the loop result and place it in a heading <code>&lt;h1&gt;</code> as a "full state name" above each section sorted by state.</p>

<p>Any help would be greatly appreciated.</p>

<p>I am getting the job done already but I am using 50 includes inserted below the 50 html STATE headings. I want to do it with only one PHP include. </p>

<p>'Example of the format of the html page:'</p>

<pre><code>&lt;h1&gt;Florida&lt;/h1&gt;
&lt;h2&gt;Company&lt;/h2&gt;
&lt;p&gt;addresse&lt;br /&gt;
City, State, Zip&lt;/p&gt;
(all of the Florida companies)

&lt;h1&gt;Georgia&lt;/h1&gt;
&lt;h2&gt;Company&lt;/h2&gt;
&lt;p&gt;addresse&lt;br /&gt;
City, State, Zip&lt;/p&gt;
    (all of the Georgia companies)
</code></pre>

<p>Here my code so far that works but it needs to be changed to work with only one PHP include for all 50 states.
I make a mysql query and select the dealers table from the database, sort by city (not sorting by state in this case because I am using a separate php include for each state). </p>

<pre><code>  &lt;?php
        //  Perform database query
            $result = mysql_query(" SELECT * 
                    FROM dealers
                    WHERE State = 'AL'
                    ORDER BY City, Company", $connection);
            if (!$result) {
                die("Database query failed: " . mysql_error());
            }       
        //  Use returned data
            while ($field = mysql_fetch_array($result)) 
            {

        //  Loop   _____________    
            if (!empty($field['Company']) )
            echo "&lt;h2&gt;".$field['Company']."&lt;/h2&gt;&lt;p&gt;";
            if (!empty($field['Address 1']) )
            echo $field['Address 1']."&lt;br /&gt;";    
            if (!empty($field['Address 2']) )
            echo $field['Address 2']."&lt;br /&gt;";    
            echo $field["City"]. ", ".$field["State"]. " ".$field["Zip"]. "&lt;br /&gt;"; 
            if (!empty($field['Phone']) )
            echo $field['Phone']."&lt;br /&gt;";
            if (!empty($field['Website']) )
            echo "&lt;a href=".$field['Website']."&gt;" ."Website: ".$field['Company'] . "&lt;/a&gt;&lt;/p&gt;";
        }
</code></pre>
