: Formule 'postcode'

Deze formule heb ik gebruikt voor het berekenen van afstand tussen postcodes…
<?php
echo “

Uw zoekresultaten

”;
if (empty($form->data[‘gemeente’])) { $form->data[‘gemeente’] = ‘%’; }
if (empty($form->data[‘afstand’])) { $form->data[‘afstand’] = ‘0’; }
echo "U zocht naar <b>" . $form->data['gemeente'] .
"</b> en eventuele omliggende gemeenten in een straal van <b>" . $form->data['afstand'] . "</b> km.<br>";

$result = mysql_query("
       SELECT * FROM `voc_gemeenten`
       WHERE `gemeente` LIKE '" . $form->data['gemeente'] ."'
       "); 

    while($row=mysql_fetch_array($result)) { 
       $resultA = mysql_query("
          SELECT *, ( 
        3959 * acos( 
        cos( radians('" . $row['latitude'] . "') ) * 
        cos( radians( latitude ) ) * 
        cos( radians( longitude ) - 
        radians('" . $row['longitude'] . "') ) + 
        sin( radians('" . $row['latitude'] . "') ) * 
        sin( radians( latitude ) ) ) 
        ) AS distance 
        FROM voc_gemeenten 
        HAVING distance <= '" . $form->data['afstand'] ."' 
        ORDER BY distance
          "); 

       echo "<table width=\"95%\"><tr valign=\"top\"><td
    width=\"115px\" valign=\"top\">Dit resulteerde in:
    </td><td><i>";
       while($rowA=mysql_fetch_array($resultA)) { 
          echo "" . $rowA['gemeente'] . ", ";
          }
       echo "</i></td></tr></table><br>";
       }
    
    echo "<p>Onderstaande personen werden gevonden die in
    aanmerking komen uit deze regio, in volgorde van afstand.
    <br>Indien je op de gebruikersnaam klikt, dan krijg je de
    vrijwilligersfiche te zien, en kan je eigen commentaar toevoegen die
    in deze lijst te zien is (nog niet actief).<br></p>";
    
         echo "<table width=\"95%\">";
         echo "<tr bgcolor= '#DDDDDD' >";
    echo "<td valign='bottom' width='250'><font color='#6a8f3d'><b><u>Naam</u></b></font></td>";
    echo "<td valign='bottom' width='111'><font color='#6a8f3d'><b><u>Telefoon</u></b></font></td>";
    echo "<td valign='bottom' width='200'><font color='#6a8f3d'><b><u>Gemeente</u></b></font></td>";
    echo "<td valign='bottom'><font color='#6a8f3d'><b><u>Opmerking</u></b></font></td>";
        echo "<tr>";
    
    $result = mysql_query("
       SELECT * FROM `voc_gemeenten`
       WHERE `gemeente` LIKE '" . $form->data['gemeente'] ."'
       "); 
    
    while($row=mysql_fetch_array($result)) { 
       $resultA = mysql_query("
       SELECT *, ( 
        3959 * acos( 
        cos( radians('" . $row['latitude'] . "') ) * 
        cos( radians( latitude ) ) * 
        cos( radians( longitude ) - 
        radians('" . $row['longitude'] . "') ) + 
        sin( radians('" . $row['latitude'] . "') ) * 
        sin( radians( latitude ) ) ) 
        ) AS distance
        FROM voc_gemeenten
        HAVING distance <= '" . $form->data['afstand'] ."' 
        ORDER BY distance
          "); 
       while($rowA=mysql_fetch_array($resultA)) { 
          $resultB = mysql_query("
          SELECT *
          FROM voc_gemeenten, voc_comprofiler
          WHERE voc_comprofiler.cb_gemeente = '" . $rowA['gemeente'] .    "'
          AND voc_gemeenten.gemeente = '" . $rowA['gemeente'] . "'
          AND voc_comprofiler.cb_ophaalder = '1'
          ");
         while($rowB = mysql_fetch_array($resultB)){
    
             echo "<tr  valign=\"top\">";
             echo "<td valign=\"top\" ><b>" .
    $rowB['firstname']  . " " .  $rowB['lastname']  . "</b>  (";
             $resultC = mysql_query("SELECT * FROM `voc_users` WHERE
    `id` = '" .  $rowB['user_id'] . "'"); 
                   while ($rowC = mysql_fetch_assoc($resultC)) {
             echo "" . $rowC['username'] . "";
             }
          echo "</b>)</td>";
    
             echo "<td valign=\"top\"><b>" .
    $rowB['cb_telefoon']  . "</b></td>";

             echo "<td valign=\"top\"><b> ";
              $resultE = mysql_query("SELECT * FROM `voc_gemeenten`
    WHERE `gemeente` = '" .  $rowB['cb_gemeente'] . "'"); 
                   while ($rowE = mysql_fetch_assoc($resultE)) {
             echo "" . $rowE['postcode'] . "";
             }
             echo " " . $rowB['cb_gemeente']  . "</b></td>";

             echo "<td valign=\"top\">" . $rowB['cb_comments']  .
    " - 
                <font color=\"#993821\">" .
    $rowB['cb_commentintern']  . "</font></td>";

             echo "<td valign=\"top\" width=\"50\" ><a
    href=\"/component/chronoconnectivity/vwedit/cc_edit_data?cid=" .
    $rowB['id']  . "\"><img src=\"/images/buttons/update.gif\"
    width=\"100%\"></a></td>";

             echo "</tr>";
             echo "<tr><td
    colspan=\"4\"></td></tr>";
          }   
       }
             echo "</table><br><br><hr>";
    }
    ?>