Welcome Guest, Not a member yet? Register   Sign In
Logic problem filtering results using datamapper
#1

[eluser]Andy78[/eluser]
Ok I have a results set of takeaways that I am looping through, the takeaway objects have the following properties id, name, address, postcode, distance, mile_cost, pizza, Chinese, Indian, kebab. If they have a pizza menu fr example it will contain 1 or a 0 if not etc

I want to filter the results in order to get the closest single pizza, Chinese, Indian and kebab selling restaurants. But also filter the results so that it doesn't show results with a distance greater than 10 and greater than the individual takeaways max deliver distance.

I have to do this in the php code rather than the mysql query and I am kinda stumped as how to do it. This is what I have so far.

Controller:
Code:
function search(){
        //load the geozip library  
        $this->load->library("geozip");
        //get the user's postcode
        $location = $this->input->post('postcode');
        //make sure post upper case and has no spaces
        $location = strip_tags($location);
     $location = strtoupper($location);
     $location = str_replace(" ", "", $location);
        
        //get all postcodes in a 10 mile radius of a postcode-location sorted by distance
        //$postcode = $this->geozip->get_zips_in_range($location, 10, SORT_BY_DISTANCE_ASC, TRUE);
        
        $takeaway = new Takeaway();
        $takeaway->select('id, name, address, postcode, distance, mile_cost, pizza, chinese, indian, kebab'); //Select only the required fields
        $takeaway->get();
        
        $data['location'] = $location;
        $data['takeaway'] = $takeaway;
        
        $this->load->view('results', $data);
    }

View:
Code:
<?php

foreach($takeaway as $takeaway){
            
            $distance = $this->geozip->get_distance($location, $takeaway->postcode);//get the distance between the two postcodes
                        
            if($distance <= $takeaway->distance && $distance <= 10){
            
                $number = 0;
              
                echo $takeaway->name.' is '.$distance.'miles away <br />';
              
             ?&gt;  
               <div class="takeaway_box">
                   <div class="takeaway_box_band">Indian</div>
                    
               </div>                
&lt;?php
            }

}
?&gt;

I guess in order to get the closest single restaurant of each type I will have to find the ones with a distance closest to zero then order them some how?

Any help on how to do this would be much appreciated.


Messages In This Thread
Logic problem filtering results using datamapper - by El Forum - 01-19-2012, 10:08 AM
Logic problem filtering results using datamapper - by El Forum - 01-19-2012, 10:57 AM
Logic problem filtering results using datamapper - by El Forum - 01-19-2012, 11:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB