Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto complete from database using CodeIgniter (Active Record)
    primarykey
    data
    text
    <p>I have a form on my website in which one is able to submit a cat. The form contains inputs such as "Name" and "Gender", but I am just trying to get the auto completion to work with the "Name" field. Here is what my jquery looks like :</p> <pre><code>$(document).ready(function() { $( "#tags" ).autocomplete({ source: '/Anish/auto_cat' }); }); </code></pre> <p>Here is what my model looks like:</p> <pre><code> public function auto_cat($search_term) { $this-&gt;db-&gt;like('name', $search_term); $response = $this-&gt;db-&gt;get('anish_cats')-&gt;result_array(); // var_dump($response);die; return $response; } } </code></pre> <p>Here is my controller:</p> <pre><code>public function auto_cat(){ $search_term = $this-&gt;input-&gt;get('term'); $cats = $this-&gt;Anish_m-&gt;auto_cat($search_term); } </code></pre> <p>And here is my view:</p> <pre><code>&lt;head&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="/resources/demos/style.css" /&gt; &lt;/head&gt; &lt;h1&gt;Anish's Page&lt;/h1&gt; &lt;form action="/Anish/create" method="POST"&gt; &lt;div class="ui-widget"&gt; &lt;label for="tags"&gt;Name&lt;/label&gt;&lt;input id="tags" type="text" name="name"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Age&lt;/label&gt;&lt;input type="text" name="age"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Gender&lt;/label&gt;&lt;input type="text" name="gender"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Species&lt;/label&gt;&lt;input type="text" name="species"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Eye Color&lt;/label&gt;&lt;input type="text" name="eye_color"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Color&lt;/label&gt;&lt;input type="text" name="color"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;Description&lt;/label&gt;&lt;input type="text" name="description"&gt; &lt;/div&gt; &lt;div&gt; &lt;label&gt;marital status&lt;/label&gt;&lt;input type="text" name="marital_status"&gt; &lt;/div&gt; &lt;br&gt; &lt;button type="submit" class="btn btn-block btn-primary span1"&gt;Add cat&lt;/button&gt; &lt;/form&gt; &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt; &lt;table class="table table-striped table-bordered table-hover"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Gender&lt;/th&gt; &lt;th&gt;Age&lt;/th&gt; &lt;th&gt;Species&lt;/th&gt; &lt;th&gt;Eye Color&lt;/th&gt; &lt;th&gt;Color&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;th&gt;Marital Status&lt;/th&gt; &lt;th&gt;Edit&lt;/th&gt; &lt;th&gt;Delete&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach ($cats as $cat):?&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo ($cat['name']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['gender']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['age']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['species']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['eye_color']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['color']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['description']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo ($cat['marital_status']);?&gt;&lt;br/&gt; &lt;/td&gt; &lt;td&gt; &lt;form action="/Anish/edit" method="post"&gt; &lt;input type="hidden" value="&lt;?php echo ($cat['id']);?&gt;" name="Anish_id_edit"&gt; &lt;button class="btn btn-block btn-info"&gt;Edit&lt;/button&gt; &lt;/form&gt; &lt;/td&gt; &lt;td&gt; &lt;form action="/Anish/delete" method="post"&gt; &lt;input type="hidden" value="&lt;?php echo ($cat['id']);?&gt;" name="Anish_id"&gt; &lt;button class="btn btn-block btn-danger"&gt;Delete&lt;/button&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach;?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>I am stuck. In my console, I am able to see this output when I type the letter 'a' if I uncomment the var_dump in my model:</p> <pre><code>array(4) { [0]=&gt; array(9) { ["id"]=&gt; string(2) "13" ["name"]=&gt; string(5) "Anish" ["gender"]=&gt; string(4) "Male" ["age"]=&gt; string(2) "20" ["species"]=&gt; string(3) "Cat" ["eye_color"]=&gt; string(5) "Brown" ["color"]=&gt; string(5) "Black" ["description"]=&gt; string(7) "Awesome" ["marital_status"]=&gt; string(1) "0" } [1]=&gt; array(9) { ["id"]=&gt; string(2) "16" ["name"]=&gt; string(5) "Anish" ["gender"]=&gt; string(2) "fe" ["age"]=&gt; string(2) "23" ["species"]=&gt; string(2) "fe" ["eye_color"]=&gt; string(2) "fe" ["color"]=&gt; string(2) "fe" ["description"]=&gt; string(2) "fe" ["marital_status"]=&gt; string(1) "1" } [2]=&gt; array(9) { ["id"]=&gt; string(2) "17" ["name"]=&gt; string(1) "a" ["gender"]=&gt; string(1) "a" ["age"]=&gt; string(1) "4" ["species"]=&gt; string(1) "a" ["eye_color"]=&gt; string(1) "a" ["color"]=&gt; string(1) "a" ["description"]=&gt; string(1) "a" ["marital_status"]=&gt; string(1) "0" } [3]=&gt; array(9) { ["id"]=&gt; string(2) "18" ["name"]=&gt; string(4) "Matt" ["gender"]=&gt; string(6) "Female" ["age"]=&gt; string(2) "80" ["species"]=&gt; string(6) "ferret" ["eye_color"]=&gt; string(4) "blue" ["color"]=&gt; string(4) "pink" ["description"]=&gt; string(5) "Chill" ["marital_status"]=&gt; string(1) "0" } } </code></pre> <p>This is an image of my table: <img src="https://i.stack.imgur.com/Mr6UZ.png" alt="This is an image of my table:"></p> <p>I appreciate all of the help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload