CodeIgniter Forums
Search Model - What am I doing wrong? - 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 Model - What am I doing wrong? (/showthread.php?tid=15132)



Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]jrutter[/eluser]
Here is my code, does everything look right? I have a form with a field name "search_terms" and I search on it and get: Message: Undefined variable: search_terms

Anyone have any tips?

Code:
<?php
class Search_model extends Model {

        var $search_terms;

        
    function Search_model()
    {
        parent::Model();
    }
    
    function search_parks()
    {
        
        $query = $this->db->query(
       "
         SELECT * FROM parks_tbl
         WHERE park_visible = 1
         AND   park_state LIKE '%". $search_terms ."%'
         OR    park_name      LIKE '%". $search_terms ."%'");
        
        return $query;

    }
    
}
?>



Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]geckzilla[/eluser]
You want to use $this->search_terms to reference it.


Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]jrutter[/eluser]
Oh, where do I use that?


Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]jrutter[/eluser]
I got it now! Thanks!


Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]jrutter[/eluser]
Ok, so now Im doing full-text mysql matching and I cant get the syntax correct.

Here is my code:

$query = $this->db->query(
"
SELECT * FROM parks_tbl
WHERE MATCH (park_name, park_description) AGAINST '$this->search_terms'
");

return $query;

Any ideas?


Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]geckzilla[/eluser]
If it's not spitting a mysql error you should be able to use
Code:
foreach($query->result() as $row) { echo $row->park_name; }



Search Model - What am I doing wrong? - El Forum - 01-27-2009

[eluser]jrutter[/eluser]
No error and no results, I think Im not getting the query from the form. Because when I stick a string into the select statement it works, but its not working by pulling the query from the search form.

Here is my controller code:

function search()
{

$data['title'] = "Search Results - Dog Friendly Parks";

// Get the search term from the submitted form
$terms = ($_GET['terms']);


//$this->Search_model->search_parks();
$data['search_query'] = $this->Search_model->search_parks($terms);
$this->load->view('park_search', $data);

}