CodeIgniter Forums
Search Form - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Search Form (/showthread.php?tid=58367)



Search Form - El Forum - 06-06-2013

[eluser]maddtechwf[/eluser]
I've got the basic form setup on my view and then I have a Model and Controller setup also. But my search is not working. Can anyone help point me in the right direction??? I have the form helper autoloaded.

View
Code:
<?php echo form_open('map/lookup'); ?>
            <input type="text" name="search-item" />
            <button class="searchbutton" tabindex="3" value="SEARCH"></button>
        &lt;?php echo form_close(); ?&gt;

Controller
Code:
public function lookup()
    {
        $search_value = $this->input->post('search-item', TRUE);
      
        $results = $this->map_model->search($search_value);
        
        if ( $results->num_rows() > 0 )
        {
            foreach ( $results->result() as $result )
            {
                $marker = array();
                $marker['position'] = $result->Lat.','.$result->Long;
                $this->googlemaps->add_marker($marker);
            }
        }
    }

Model
Code:
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;
        }



Search Form - El Forum - 06-06-2013

[eluser]jairoh_[/eluser]
try print_r( $results ), if empty then there's something wrong w/ the query.