How can I get this code to return more than one of the same UK postcode?
<p>On our website we have a feature where people can enter their UK postcode and be given a list of the ten nearest healers to them. It works well apart from the fact that if two or more healers share the same postcode, it only returns one of them.</p>

<p>I believe it is this function that is causing the problem:</p>

<pre><code>function postcode_closest ($needle,$haystack) // $needle = user entered postcode.
                                              // $haystack = list of postcodes.
{
    if (!$needle||!$haystack) { return; }
    if (!is_array($haystack)) { return; }

    foreach ($haystack as $postcode)
    {
        $results[$postcode]=postcode_distance($needle,$postcode);
    }

    asort($results);

    return $results;
}
</code></pre>

<p><strong>EDIT:</strong> Here is the part of the main code where this function is called:</p>

<pre><code>$query = mysql_query("SELECT latitude, longitude FROM postcodes WHERE outcode='$outcode'");
if (mysql_fetch_array($query))
{
    $closest=postcode_closest($outcode,$postcodes); // Call the postcode_closest function to get a list of $postcodes ordered by distance from $outcode
    echo "&lt;table&gt;\n&lt;thead&gt;\n&lt;tr&gt;&lt;th scope='col'&gt;Name&lt;/th&gt;&lt;th scope='col'&gt;Town&lt;/th&gt;&lt;th scope='col'&gt;Telephone&lt;/th&gt;&lt;th scope='col'&gt;Email&lt;/th&gt;&lt;th scope='col'&gt;Distance&lt;/th&gt;&lt;/tr&gt;\n&lt;/thead&gt;\n&lt;tbody&gt;\n";
    $i = 0;
    foreach ($closest as $key =&gt; $val)
    {
        if ($i &lt; 10) // Display this number of results from the list.
        {
            $query = mysql_query("SELECT member, postcode, name, town, telephone, email FROM healers WHERE postcode = '$key'");
            $one = mysql_fetch_array($query);

            // Linkify email addresses, but only if they exist.
            if ($one[5])
            {
                $one[5] = "&lt;a href='mailto:$one[5]'&gt;$one[5]&lt;/a&gt;";
            }

            echo "&lt;tr&gt;&lt;td&gt;$one[2]&lt;/td&gt;&lt;td&gt;$one[3]&lt;/td&gt;&lt;td&gt;$one[4]&lt;/td&gt;&lt;td&gt;$one[5]&lt;/td&gt;&lt;td&gt;$val Miles&lt;/td&gt;&lt;/tr&gt;\n";
            $i++;
        }
    }
    echo "&lt;/tbody&gt;\n&lt;/table&gt;\n";
}
</code></pre>

<p>If I understand correctly, $postcode is being used as the <em>key</em> for the $results array which is why each postcode will only appear once.</p>

<p>Does that make sense? How would I go about altering the code so that healers who share a postcode all appear on the list? I've inherited this code and my knowledge of programming is small. I can post the full code if necessary.</p>

<p>Thanks.</p>
