• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search Model - What am I doing wrong?

#1
[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;

    }
    
}
?>

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

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

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

#5
[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?

#6
[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; }

#7
[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);

}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.