Do you have an idea how to pull data from mysql, put it in an array then feed it in an autocomplete field?
I have tried hardcoded the values but what I'm thinking is when I add a new record, I have to re-code again the array. I'm a newbie in PHP so I beg your pardon.
Kindly check what I've tried so far:
protected function jsGenerateResourcesAutocomplete(){
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "SELECT employee_name FROM employee" ;
mysql_select_db('test', $conn);
$retval = mysql_query($sql);
$row = mysql_fetch_assoc($retval);
if(!$retval )
{
die('Could not select data: ' . mysql_error());
}
$employeeNames = $this->employeeNames;
$html = ""; $html .= 'var employeenames = [' . PHP_EOL;
foreach ($employeeNames as $employeeName) {
$html .= '"' . $employeeName-> $array . '",' . PHP_EOL;
}
$html .= '];';
$html .= '$(".resource-input input").autocomplete({source: employeenames});' .PHP_EOL;
$html .= '});' . PHP_EOL;
$html .= '</script>' . PHP_EOL;
return $html;
}
I believe something in this line:
$html .= '"' . $employeeName-> $array . '",' . PHP_EOL;
I have to put forth the array but I have no idea how to do it. Any help is truly appreciated. Thanks.
json_encode($array);mysql_family of functions. Now would be a great time to switch to PDO or mysqli.