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
I want to gather the "Name" column from SQL for distinct data only
Here is my MySQL query
$data['typeahead'] = $this->db->query('SELECT DISTINCT Name from table')->result_array();
Here is the output it gives on var_dump
array(287) {
[0]=> array(1) { ["Name"]=> string(16) "'67 Shelby GT500" }
[1]=> array(1) { ["Name"]=> string(8) "Tooligan" }
[2]=> array(1) { ["Name"]=> string(24) "'67 Pontiac Firebird 400" }
[3]=> array(1) { ["Name"]=> string(17) "Volkswagen Beetle" }
}
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.
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.
^^ Solved
Issue now:
Typeahead isn't pulling data from array
controller code:
$name_array = $this->db->query('SELECT DISTINCT Name from table')->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;
View Code:
<input type="text" class="span3 search-query" placeholder="Search" id="typeahead" data-provide="typeahead" data-source="<?php echo $typeahead; ?>"><button type="submit" class="btn"><i class="icon-search"></i></button>