title: Codeigniter Search box or search form
body: <p>I am trying to create a search form in Codeigniter. I created a textbox where the user can input the title and author of the book they want to search. This is my code so far, is my code right or is it not?</p>
  
  <p>Controller:</p>
  
  <pre><code>function searchBooks() {
      $postlist['bookSearch'] = $this-&gt;view_book_model-&gt;getSearchBook($this-&gt;input-&gt;post('search'));
      $this-&gt;load-&gt;view('searchbooks.php', $postlist);
  }
  </code></pre>
  
  <p>Model:  </p>
  
  <pre><code>function getSearchBook($searchBook) {
      $select_query = "Select * from books where Title = '.$searchBook.' ";
      $query = $this-&gt;db-&gt;query($select_query);
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;input type="text" class="searchBox" id="searchBox"&gt; &lt;/input&gt;
  &lt;input type="submit" value="Search" class="btnInput" id="btnInput"&gt; &lt;/input&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;?php
  echo '&lt;hr&gt;';
  echo '&lt;h3&gt; Book List &lt;/h3&gt;';
  echo '&lt;table id="maintable"  class="table"&gt;';
  echo '&lt;th&gt; Book ID&lt;/th&gt;';
  echo '&lt;th&gt; Book Title &lt;/th&gt;';
  echo '&lt;th&gt; Book Author &lt;/th&gt;';
  echo '&lt;th&gt; # of Copies &lt;/th&gt;';
  echo '&lt;th&gt; Available Copy &lt;/th&gt;';
  
  foreach($bookSearch as $rows) {
      echo '&lt;tr&gt;
              &lt;td&gt;'.$rows-&gt;BookID.'&lt;/td&gt;
              &lt;td&gt;'.$rows-&gt;Title.'&lt;/td&gt;
              &lt;td&gt;'.$rows-&gt;Author.'&lt;/td&gt;
              &lt;td&gt;'.$rows-&gt;Qty.'&lt;/td&gt;
              &lt;td&gt;'.$rows-&gt;OnHand.'&lt;/td&gt;
          &lt;/tr&gt;';
  }
  echo '&lt;/table&gt;';
  ?&gt;
  </code></pre>
  
  <p>I use ajax to retrieve the input entered by the user in the search box. The problem is that i don't know how to code my model in terms of searching for the title and author of the book searched by the user.</p>