As a hobby project I started making a website for a company. I am not very advanced in making complicated codes for website but I wanted to give it a try.

I have a zip code database from the Netherlands with over 471000 records in it. I use the haversine formula to look up which postal codes are within the radius of 13 km and then I select every user from the database that has a postalcode in this result. But the formula takes 6 secs to load all the results. How can I speed this process up?

**Code below:**

```
$finder = $mysqli->query("SELECT lat, lng FROM postcodetabel WHERE postcode = '$s' OR plaats = '$s'");
$finder1 = mysqli_fetch_assoc($finder);
$latitude = $finder1['lat'];
$longitude = $finder1['lng'];
$query = $mysqli->query("SELECT postcode, (
      6371 * acos (
      cos ( radians('$latitude') )
      * cos( radians( lat ) )
      * cos( radians( lng ) - radians('$longitude') )
      + sin ( radians('$latitude') )
      * sin( radians( lat ) )
    )
) AS distance
FROM postcodetabel
HAVING distance < 12
ORDER BY distance ASC");

$quertie = $mysqli->query("SELECT bigav, id, naam, email, bedrijfsnaam, telnummer FROM gebruikers WHERE postcode = '$postcode' AND status = 1 AND soort LIKE '%" . $soort . "%'");
while($quertie2 = mysqli_fetch_assoc($quertie)) { echo '
<div class="kapper">
    <div class="kapperfoto"><img src="/vluggeknipt/ondernemer/pagina/uploads/'.$quertie2['bigav'].'" style="width:100px;height:100px;"></div>
    <div class="boektekst">
        <font class="headingkap"><strong><a href="?page=profiel&id='.$quertie2['id'].'">Naar profiel &raquo;</a></strong></font><br/>
    </div>
    <div class="kappertext">
        <font class="headingkap"><a href="?page=profiel&id='.$quertie2['id'].'"><strong>'.$quertie2['naam'].'</strong></a></font><br/>
        <i class="mobhide">'.$quertie2['email'].' - '.$quertie2['telnummer'].'</i><br/>
        <i class="mobhide">'.$quertie2['bedrijfsnaam'].'</i>
    </div></div><br/>

    '; }

```

Thanks in advance!