Welcome Guest, Not a member yet? Register   Sign In
GoogleMaps API V3 and CodeIgniter
#4

[eluser]maddtechwf[/eluser]
Model (Map_model.php)
Code:
<?php
    class Map_model extends CI_Model{
        function __construct()
        {
            parent::__construct();
        }
        
        // param = NULL is to make the parameter optional.
        function get_coordinates($point_id = NULL)
        {
            $return = array();
            $this->db->select("Lat,Long,Name,Address1,City,State,Zip");
            $this->db->from("Points");
            $query = $this->db->get();
            
            if($query->num_rows() > 0)
            {
                foreach ($query->result() as $row){
                    array_push($return, $row);
                }
            }
            
            return $return;
        }
        
      
        //Get points in a specific category
        function get_category_points($category_id)
        {
            $return = array();
            
            //DB Connection
            //$this->db->select('Lat,Long,Name,Address1,City,State,Zip');
            //$this->db->from('Points');
            //$this->db->join('Point2Category','Point2Category.Point_ID = ');
            //$this->db->where('Category_ID='.$category_id);
            //$point_ids = $this->db->get();
            
            if ( $point_ids->num_rows() > 0 )
            {
                foreach ( $point_ids->result() as $point )
                {
                    $points = get_cordinates($point);
                }
                
                if ($points->num_rows() > 0)
                {
                    foreach ( $points->results() as $p )
                    {
                        array_push($return, $p);
                    }
                }
            }
            
            return $return;
        }
        
        //Get Gategories
        function get_categories($cat_type)
        {
            $return = array();
            
            //DB Connection
            $this->db->select('ID,Name');
            $this->db->from('Category');
            $this->db->where('Type', $cat_type);
            $category_items = $this->db->get();
            
            if ( $category_items->num_rows() > 0)
            {
                foreach ( $category_items->result() as $item )
                {
                    $return[$item->ID] = $item->Name;
                }
            }
            return $return;
        }
        
        function search($term)
        {
            $return = array();
            
            //DB Connection
            $this->db->select("Lat,Long,Name,Address1,City,State,Zip");
            $this->db->from("Points");
            $this->db->like('Name', $term);
            // $this->db->like('Tags', $term);
            $search_results = $query = $this->db->get();
            
            if ( $search_results->num_rows() > 0 )
            {
                foreach ( $search_results->result() as $result )
                {
                    array_push($return, $result);
                }
            }
            
            return $return;
        }
    }

View (map_view.php)
Code:
<?= anchor('/Map/all_points', 'All Points'); ?>


Messages In This Thread
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 06:25 AM
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 06:33 AM
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 07:08 AM
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 07:10 AM
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 08:05 AM
GoogleMaps API V3 and CodeIgniter - by El Forum - 06-12-2013, 01:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB