I am trying to find out where to put my code in joomla

I have a component installed and a search module

I have made a type of store locater ( find the stores with in a set distace of the members zip/postcode)

i would like to add this to the search module that is already there, but having problems understanding where this code should go

i have put the form new form in modules/MODNAME/tmpl/default.php - under the existing form for now just for testing

I would like to use the same view that the search form already uses

but were do add the code that runs the sql query get the results and display them in the existing search view

sorry if this is a stupid question new to coding and strugling to understand how this works