Welcome Guest, Not a member yet? Register   Sign In
Need help with basic search query related stuff...
#1

[eluser]theif_of_always[/eluser]
I have a table in the database I am trying to query information from
using a keyword value from a $_POST array. But, I am trying to combine active records: "like," "order_by (in asc order)" and "get" and I keep getting some kind of index error. I know how to do them individually (see below), but how would I use them together? I am passing the post array to this function as the method argument. And I want to return query object to calling function.

Oh, and I am still a little fuzzy on what the "like" active record does. I read the definition provided by CI and wasn't sure what it was doing. Can someone explain it to me in layman's terms?

Any help appreciated. Thanks.

Code:
public function search_books($post)
   {
    
  $this->db->get('bookInformation');
  
  return $this->db->where("bookTitle", $post['bookTitle']);
  
  $this->db->like('bookTitle', 'bookTitle');
  
  $this->db->order_by("bookTitle", "asc");
  
  
    }
#2

[eluser]Aken[/eluser]
You shouldn't pass query parameters directly from the $_POST array. Sanitize it before using it.

LIKE is a pattern search, rather than an equality comparison (= or !=). http://theopentutorials.com/tutorials/my...-operator/

Code:
$this->db->order_by('bookTitle', 'ASC');
$query = $this->db->get_where('bookInformation', array('bookTitle'), $post['bookTitle']);

return $query->result();
#3

[eluser]theif_of_always[/eluser]
here is my code:

Code:
public function search_books($post)
   {
    
   $this->db->order_by('bookTitle', 'ASC');
             $query = $this->db->get_where('bookInformation', array('bookTitle'), $post['bookTitle']);

            return $query->result();
    

    }

Here is the error I get:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: bookTitle

Filename: models/searchmodel.php

Line Number: 10
#4

[eluser]Aken[/eluser]
It's the same code that you were using, you tell me!
#5

[eluser]weboap[/eluser]
Code:
$query = $this->db->get_where('bookInformation', array('bookTitle'=>$post['bookTitle']) );

now your issue is in the function calling this model function, it look like you are passing an array but not specifying

Code:
$post['bookTitle'] = 'something';
//then.....
$this->model_name->search_books($post);
#6

[eluser]Aken[/eluser]
Gah, don't just hand them the answer! lol
#7

[eluser]weboap[/eluser]
sorry man, didn't mean to !!!! next time




Theme © iAndrew 2016 - Forum software by © MyBB