Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Bootstrap, CodeIgniter - Typeahead data pulling from MySQL
    primarykey
    data
    text
    <p>I am attempting to query SQL to get an array of values to use for typeahead and I'm apparently missing the fundamentals of arrays because it's not giving me even close to the results that I expect</p> <p>I want to gather the "Name" column from SQL for distinct data only</p> <p>Here is my MySQL query</p> <pre><code>$data['typeahead'] = $this-&gt;db-&gt;query('SELECT DISTINCT Name from table')-&gt;result_array(); </code></pre> <p>Here is the output it gives on var_dump</p> <pre><code>array(287) { [0]=&gt; array(1) { ["Name"]=&gt; string(16) "'67 Shelby GT500" } [1]=&gt; array(1) { ["Name"]=&gt; string(8) "Tooligan" } [2]=&gt; array(1) { ["Name"]=&gt; string(24) "'67 Pontiac Firebird 400" } [3]=&gt; array(1) { ["Name"]=&gt; string(17) "Volkswagen Beetle" } } </code></pre> <p>The only thing I'm trying to do is build an array with the data from the columns. I'm using CodeIgniter for FrameWork and will be using Bootstrap's JS to work with the typeahead, but I'm stuck on the data array section.</p> <p>Any help would be greatly appreciated, I've found numerous tutorials on how to use non MySQL arrays as typeahead, but none working with MySQL.</p> <p>^^ Solved</p> <p>Issue now:</p> <p>Typeahead isn't pulling data from array</p> <p>controller code:</p> <pre><code> $name_array = $this-&gt;db-&gt;query('SELECT DISTINCT Name from table')-&gt;result_array(); $typeahead_string = ''; foreach ($name_array as $name) { $formatted_name = '"' . $name['Name'] . '", '; $typeahead_string .= $formatted_name; } $option_list = "[" . rtrim($typeahead_string, ", ") . "]"; $data['typeahead'] = $option_list; </code></pre> <p>View Code:</p> <pre><code>&lt;input type="text" class="span3 search-query" placeholder="Search" id="typeahead" data-provide="typeahead" data-source="&lt;?php echo $typeahead; ?&gt;"&gt;&lt;button type="submit" class="btn"&gt;&lt;i class="icon-search"&gt;&lt;/i&gt;&lt;/button&gt; </code></pre>
    singulars
    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.
 

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