Jump to content

search by id


blad
 Share

Recommended Posts

Hello! 
 
My first post on the forum and I start with a question. 
I'm trying to modify the module datatable by Soma and I want to search  by $page->id. 
 
code:
 
if( $this->input->get->sSearch ) {
$q = $this->sanitizer->text($this->input->get->sSearch);
$selector .= "title|body%=$q,";
}

my code (doesn´t work):

if( $this->input->get->sSearch ) {
$q = $this->sanitizer->text($this->input->get->sSearch);
$selector .= "id|title|body%=$q,";
}
 
$thanks->ryan;
$thanks->soma;
 
And please excuse my bad English
Link to comment
Share on other sites

@blad - welcome to the forums!

not totally sure here, but could possibly be an issue with trying to sanitize as text, since ID is (int).

have you tried it without the sanitizer, and also have you tried it with different operators like *= and ~=?'

  • Like 1
Link to comment
Share on other sites

Id is integer and not fulltext. You can't mix them with % but maybe with * . But you may need to have some additional logic to check if search is an Id or text.

  • Like 1
Link to comment
Share on other sites

Hi Blad,

You can do this with some additional logic:

if( $this->input->get->sSearch ) {
  $q = $this->sanitizer->text($this->input->get->sSearch);
  if (is_numeric($q)) {
    $selector .= "id=$q,";
  } else {
    $selector .= "title|body%=$q,";
  }
}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...